<?php

	class GroupController
	{
		private $groupInfoModel;
		private $attachmentModel;
		private $groupMembersModel;
		private $topicModel;
		private $topicCommentsModel;
		private $autoUidModel;
		private $diaryListCacheModel;
		private $userStatisticsModel;
		private $diaryBodyModel;
		private $diaryAttachmentModel;
		private $diaryListModel;
		private $followModel;
		private $shopModel;
		private $voteModel;
		private $childCommentModel;
		
		function __construct()/*{{{*/
		{
			$this->groupInfoModel       	=   new GroupInfoModel();
			$this->attachmentModel          =   new AttachmentModel();
			$this->groupMembersModel        =   new GroupMembersModel();
			$this->topicModel          	=   new TopicModel();
			$this->topicCommentsModel       =   new TopicCommentsModel();
			$this->autoUidModel       	=   new AutoUidModel();
			$this->diaryListCacheModel      =   new DiaryListCacheModel();
			$this->tokenUserCacheModel  	=   new TokenUserCacheModel();
			$this->userStatisticsModel  	=   new UserStatisticsModel();
			$this->diaryBodyModel           =   new DiaryBodyModel();
			$this->diaryAttachmentModel     =   new DiaryAttachmentModel();
			$this->diaryListModel           =   new DiaryListModel();
			$this->followModel              =   new FollowModel();
			$this->shopModel                =   new ShopModel();
			$this->voteModel                =   new VoteModel();
			$this->childCommentModel        =   new ChildCommentModel();
			$this->actions 		=   array(
			    'createGroup','getGroupInfo','editGroup','removeGroup','findGroup','getMembersList',
                'getGroupMeList','getGroupMeCreate','getTopicList','addTopic','getTopicInfo','getTopicCommentList','allGroup',
                'postTopicComment','removeTopicComment','getMyTopics','removeTopic', 'quitGroup', 'quitGroupUser', 'getGroupUser', 'addGroup',
                'stickTopic', 'getCommentMeList', 'getFavoriteTopicList','addFavoriteTopic','removeFavoriteTopic', 'getRecentTopicList',
                'getUnpublishedTopics','searchTopic','getMyCommentsList','getGroupCategories','getRecommendTopics', 'giveUserManage',
                'getGroupsByTag','getRecommentGroups','voteTopic','changeGroupUser','choiceGroup','getGroupByCategory','getAllGroupCategory',
                'stickGroup','unStickGroup','getChildComments','removeManage'
            );
		}/*}}}*/
		
		public function callApi($param)/*{{{*/
		{
			$ac = $param['action'];
			# check $do /*{{{*/
			$doCheck    =   $this->checkAction($ac);
			if (!empty(AC::$errorNo))
			{
				return  $doCheck;
			} /*}}}*/
		
			return $this->$ac($param);
		}/*}}}*/
		
		/**
		 * 话题最新
		 * @param unknown $info
		 * @return boolean|StdClass|multitype:
		 */
		public function getTopicSquareList ($info) {
		    $host_uid = AC::HOST_UID;
		    $uid      = $host_uid;
		    // check params
		    if ($uid < 1){
		        AC::$errorNo    =   'GRC001';
		        return FALSE;
		    }
		    
		    // 分页参数
		    list($id, $start, $length) = UK::assemblePageData($info);
		    $category = 0;
		    
		    // 请求列表
		    $list = $this->topicModel->getTopicSquareList( $category, $id, $start, $length );
		    if (empty($list)) {
		        return (Object) array();
		    }
		    
		    $result =   array();
		    // 组装话题列表信息,并将话题图片获取
		    foreach ($list as $value) {
    			$res    = $this->topicModel->topicAddRedis(array('tid' => $value));
    			if (empty($res)){
    			    continue;
    			}
    			$topics[]     = $this->topicData($res, 1);
		    }
		    $result['topics'] = $topics;
		    $result['counts'] = count($topics);
		    
		    // 更新用户活跃时间
		    $this->autoUidModel->updateUserLastActivity($host_uid);
		    return $result;
		}/*}}}*/
		
		/**
		 * 收藏话题/楼层
		 * @param unknown $info
		 * @return boolean
		 */
		private function addFavoriteTopic($info){
		    // init params
		    $uid = $tid = $author_uid = $position = 0;
		    isset($info['uid'])    &&    $uid    =    intval($info['uid']);
		    isset($info['tid'])    &&    $tid    =    intval($info['tid']);
		    isset($info['author_uid'])  &&    $author_uid  =    intval($info['author_uid']);
		    isset($info['position'])    &&    $position    =    intval($info['position']);
		    $position ++;
		    
		    // check params
		    if ($uid < 1 || $tid < 1){
		        AC::$errorNo    =   'GRC001';
		        return FALSE;
		    }
		    
		    // 是否是本人登录
		    if ($uid != AC::HOST_UID){
		        AC::$errorNo    =   'GRC005';
		        return FALSE;
		    }
		    
		    // 获取话题详情
		    $topicInfo    =    $this->topicModel->topicAddRedis(array('tid' => $tid));
		    if (empty($topicInfo)){
		        AC::$errorNo    =   'GRC002';
		        return FALSE;
		    }
		    
		    // 判断收藏的是话题还是楼层
		    if ($position <= 1 && $author_uid < 1){
		        // 不能收藏自己的话题
		        if ($info['uid'] == $topicInfo['uid']){
		            AC::$errorNo    =   'GRC004';
		            return FALSE;
		        }
		        
		        $rUid = $topicInfo['uid'];
		    }else{
		        // 收藏楼层时查看楼层是否已被删除
		        $commentInfo = $this->topicCommentsModel->getCommentUid(array('tid' => $tid, 'position' => $position, 'author_uid' => $topicInfo['uid']));
		        if (empty($commentInfo)) {
		            AC::$errorNo    =   'GRC006';
		            return FALSE;
		        }
		        
		        $rUid = $author_uid;
		    }

		    // 被拉黑不能收藏
		    $access =   $this->checkAccessPremission($rUid);
		    if (empty($access)) return  FALSE;
		    
		    // 获取rUid的用户信息
		    $authorInfo    =    $this->autoUidModel->getUserInfo($rUid);
		    if (!isset($authorInfo['nickname'])){
		        AC::$errorNo    =   'GRC002';
		        return FALSE;
		    }
		    
		    // 组装数据
		    $data = array(
		            'uid'    =>    $uid,
		            'tid'    =>    $tid,
		            'position'    =>    $position,
		            'author_uid'  =>    $rUid,
		            'author_name' =>    UK::getstr($authorInfo['nickname'], 24, '', 1),
		            'title'       =>    $topicInfo['title']
		    );
		    
		    // 判断收藏情况
		    $favoriteInfo    =    $this->topicModel->getFavoriteTopicInfo($data);
		    
		    // 首次收藏
		    if (empty($favoriteInfo)){
		        $result = $this->topicModel->addFavoriteTopic($data);
		    }
		    
		    // 已经被收藏
		    if (!empty($favoriteInfo) && $favoriteInfo['status'] == 0){
		        AC::$errorNo    =   'GRC011';
		        return FALSE;
		    }
		    
		    // 曾经收藏但被取消
		    if (!empty($favoriteInfo) && $favoriteInfo['status'] == 1){
		        $result = $this->topicModel->setFavoriteTopic($data);
		    }
		    
		    // 收藏类别的轮询数字
		    if ($position <= 1){
		        AC::$userStatistics[$info['uid']]['topicFavorTimes']    =   1;
                $this->topicModel->editLikeTimes(['tid' => $data['tid'], 'like_num' => 1]);
		    }else{
		        // 更新计数
		        $data['favorites'] = 1;
		        $data['author_uid'] = $topicInfo['uid'];
		        $this->topicModel->updateFavoriteCommentCount($data);
		        AC::$userStatistics[$info['uid']]['commentFavorTimes']  =   1;
		    }
		    
		    return $result;
		}
		/**
		 * 获取收藏的话题列表
		 * @param unknown $info
		 * @return boolean|unknown
		 */
		public function getFavoriteTopicList($info){
		    if (intval($info['uid']) < 1){
		        AC::$errorNo    =   'GRC001';
		        return FALSE;
		    }
		    
		    // 被拉黑不能看列表
		    $access =   $this->checkAccessPremission($info['uid']);
		    if (empty($access)) return  FALSE;
		    
		    $result =  $this->topicModel->getFavoriteTopic($info);
		    $data   =  array();
		    $check  =  0;
		    if (!empty($result)){
    		    // 重建返回数据格式
    		    foreach ( $result as $val ){
    		        $val['tid']              =  $val['topic_id'];
    		        $topicInfo               =  $this->topicModel->topicAddRedis($val);
    		        if (empty($topicInfo))
    		        {
                        continue;
//    		        	$topicInfo	=	array(
//    		        	        'id'    =>  	$val['id'],
//       		        		'uid'	=>	$val['favorite_uid'],
//    		        		'gid'	=>	99,
//    		        		'tid'	=>	$val['topic_id'],
//    		        		'title'	=>	$val['title'],
//    		        		'abbreviation'=>'原话题已被删除!',
//    		        	        'time'  =>  	$val['time'],
//    		        	        'status'=>  	$val['status'],
//    		        	);
    		        	$check = 1;
    		        }
    		        $data['topics'][] =  $this->topicData($topicInfo, $check);
    		    }

    		    $data['counts']    =    count($data['topics']);
		    }
		    if (empty($result)){
		        $data['topics']    =    (Object) array();
		    }
		    return $data;
		}
		
		/**
		 * 取消收藏
		 * @param unknown $info
		 * @return boolean
		 */
		public function removeFavoriteTopic($info){
		    // init params
		    $uid = $tid = $position = 0;
		    isset($info['uid'])    &&    $uid    =    intval($info['uid']);
		    isset($info['tid'])    &&    $tid    =    intval($info['tid']);
		    isset($info['position'])    &&    $position    =    intval($info['position']);
		    $position ++;
		    
		    // check params
		    if ($uid < 1 || $tid < 1){
		        AC::$errorNo    =   'GRC001';
		        return FALSE;
		    }
		    
		    // 是否是本人登录
		    if ($uid != AC::HOST_UID){
		        AC::$errorNo    =   'GRC005';
		        return FALSE;
		    }
		    
		    // 获取话题详情(无关状态)
		    $topicInfoWithoutStatus = $this->topicModel->getTopicInfoWithoutStatus($tid);
		    
		    // 组装数据
		    $data = array(
		            'uid'    =>    $uid,
		            'tid'    =>    $tid,
		            'position'    =>    $position
		    );
		    
		    // 判断收藏情况
		    $favoriteInfo    =    $this->topicModel->getFavoriteTopicInfo($data);
		    
		    // 判断取消条件
		    if (!empty($favoriteInfo) && $favoriteInfo['status'] == 0){
		        // 取消收藏,修改状态
		        $data['status'] = 1;
		        $result = $this->topicModel->setFavoriteTopic($data);
		    }else{
		        AC::$errorNo    =   'GRC011';
		        return FALSE;
		    }
		    
		    if ($position <= 1){
		        AC::$userStatistics[$info['uid']]['topicFavorTimes']    =   -1;
                $this->topicModel->editLikeTimes(['tid' => $data['tid'], 'like_num' => -1]);
		    }else{
		        // 更新计数
		        $data['author_uid'] = $topicInfoWithoutStatus['uid'];
		        $data['favorites'] = -1;
		        $this->topicModel->updateFavoriteCommentCount($data);
		        AC::$userStatistics[$info['uid']]['commentFavorTimes']  =   -1;
		    }
		    return $result;
		}

		/**
		 * 获取最近浏览的话题列表
		 * @param unknown $info
		 * @return boolean|unknown
		 */
		private function getRecentTopicList($info){
		    if (intval($info['uid']) < 1){
		        AC::$errorNo    =   'GRC001';
		        return FALSE;
		    }
		    $start = isset($info['start']) ? intval($info['start']) : 0;
		    $length = isset($info['length']) ? intval($info['length']) : 20;
		    
		    // 被拉黑不能看列表
		    $access =   $this->checkAccessPremission($info['uid']);
		    if (empty($access)) return  FALSE;
            $length = $start + $length - 1;
		    $tids = $this->diaryListCacheModel->getUserViewTopic($info['uid'], $start, $length);
		    $data   =  array();
		    if(empty($tids)){
		    	return (object)array();
		    }
		    foreach ($tids as $tid) {
		    	$topicInfo =  $this->topicModel->topicAddRedis(['tid'=>$tid]);
		    	if (empty($topicInfo)) {
		        	continue;
		        }
		        $data['topics'][] =  $this->topicData($topicInfo);
		    }
		    $data['counts']    =    count($data['topics']);
		    return $data;
		}
		
		/**
		 * 加入圈子
		 * @param unknown $info[gid] $info[uid]
 		 * @return boolean|Ambigous <boolean, unknown>
 		 * GRC034 不能再次加入此圈子
		 */
		private function addGroup($info){
		    if ( intval($info['uid']) < 1 || intval($info['gid']) < 1){
		        AC::$errorNo    =   'GRC001';
		        return FALSE;
		    }
		    // 圈子是否存在
		    $groupInfo  =   $this->groupInfoModel->groupAddRedis($info['gid']);
		    if (empty($groupInfo))
		    {
		    	AC::$errorNo = 'GRC012';
		    	return FALSE;
		    }

		    $userGroups     = $this->groupMembersModel->getUserGroupAllCache($info['uid']);
		    $userGroupCache = $this->checkUserInitGroupsOrmUids($info['uid'], $userGroups);
		    $gids = array();
		    if ($userGroupCache['gids']) {
		        $gids =  $userGroupCache['gids'];
		    }
            // 超出圈子加入上限
		    if (count($gids) >= AC::USER_JOIN_GROUP_NUM){
		    	AC::$errorNo    =   'GRC003';
		    	return FALSE;
		    }
		    // 已经加入过
		    if (in_array($info['gid'],$gids)){
		    	return true;
		    }

		    $uids = $this->diaryListCacheModel->getGroupBlockUser($info['gid']);
		    if(in_array($info['uid'], $uids)){
                AC::$errorNo    =   'GRC031';   //被踢出用户不能再次加入
                return FALSE;
            }
            $this->diaryListCacheModel->deletePauseGroup();
            $pauseList = $this->diaryListCacheModel->getPauseGroupList();
            if(in_array($info['gid'], $pauseList)) {
                AC::$errorNo    =   'GRC032';   //圈子已被封禁，无法加入
                return FALSE;
            }
            $info['gtype'] = 1;
            $result =  $this->groupMembersModel->addMembers($info);
		    
		    // 更新缓存
            array_unshift($gids, $info['gid']);
		    
		    // 更新数据库
		    $this->addMemberNum($info,$gids);
		    
		    // 关注管理员
		    $manage_uid = $groupInfo['mUid'];
		    if ($manage_uid){
		        $this->meFollow($info['uid'], $manage_uid);
		    }
		    return $result;
		}
		
		/**
		 * 退出圈子
		 * GRC030 未加入圈子不能退出圈子
		 * @param unknown $info[gid] $info[uid]
		 * @return boolean|Ambigous <boolean, unknown>
		 */
		private function quitGroup($info){
		    if ( intval($info['uid']) < 1 || intval($info['gid']) < 1){
		        AC::$errorNo    =   'GRC001';
		        return FALSE;
		    }
		    // 圈子是否存在
		    $groupInfo  =   $this->groupInfoModel->groupAddRedis($info['gid']);
		    if (empty($groupInfo))
		    {
		    	AC::$errorNo = 'GRC012';
		    	return FALSE;
		    }

            //圈子队长不能退出
            if($groupInfo['uid'] == $info['uid']) {
                AC::$errorNo    =   'GRC027';
                return FALSE;
            }
		    //未加入不能退出
		    $userGroups     = $this->groupMembersModel->getUserGroupAllCache($info['uid']);
		    $userGroupCache = $this->checkUserInitGroupsOrmUids($info['uid'], $userGroups);
		    $gids = array();
		    if ($userGroupCache['gids']) {
		        $gids =  $userGroupCache['gids'];
		    }
		    if (!in_array($info['gid'], $gids) || AC::HOST_UID == 2){
		    	AC::$errorNo    =   'GRC004';
		        return FALSE;
		    }

		    $info['status']    =    '1';
		    $info['gtype']     =    '1';
		    $result =  $this->groupMembersModel->setGroupMember($info);
		    
		    // 更新缓存
		    $newGids = array_diff($gids, array($info['gid']));
		    
		    // 更新数据库
		    $this->delMemberNum($info, $newGids);

            //设置完成更新用户圈子信息的缓存
            if(isset($userGroups['topGid']) && !empty($userGroups['topGid'])) {
                $topGids = explode(',', $userGroups['topGid']);
                $topGids = array_diff($topGids, array($info['gid']));
                if(empty($topGids)){
                    $data = ['topGid' => ''];
                }else{
                    $data = [
                        'topGid' => implode(',', $topGids)
                    ];
                }
                $this->diaryListCacheModel->addGroupUserCache($info['uid'], $data);
            }
            //设置圈子管理员
            $uidList =  [];
            if(!empty($groupInfo['mUids'])) {
                $uidList = explode(',', $groupInfo['mUids']);
            }
            $mUids = array_diff($uidList, array($info['uid']));
            if(count($mUids) > 0) {
                $mUids = implode(',', $mUids);
            }else{
                $mUids = '';
            }
            $result = $this->groupInfoModel->editGroup(array('gid'=>$info['gid'], 'mUids'=>$mUids));
            if($result) {
                $this->diaryListCacheModel->setGroupCount($info['gid'], 'mUids', $mUids);
                //设置完成更新用户圈子缓存
                if (isset($userGroupsInfo['manageGid']) && !empty($userGroupsInfo['manageGid'])) {
                    $manageGid = explode(',', $userGroupsInfo['manageGid']);
                    $key = array_search($info['gid'], $manageGid);
                    if ($key) {
                        array_slice($manageGid, $key, 1);
                    }
                    if (empty($manageGid)) {
                        $data = ['manageGid' => ''];
                    } else {
                        $data = [
                            'manageGid' => implode(',', $manageGid)
                        ];
                    }
                    $this->diaryListCacheModel->addGroupUserCache($info['uid'], $data);
                }
            }
		    // 取消关注管理员
		    $manage_uid = $groupInfo['mUid'];
		    if ($manage_uid){
		        $this->removeFollow($info['uid'], $manage_uid);
		    }
		    if($result){
		        return true;
            }
            return false;
		}

		/**
		 * 踢出圈子
		 * @param unknown $info[gid] $info[uid]
		 * @return boolean|Ambigous <boolean, unknown>
		 */
		private function quitGroupUser($info){
		    if ( intval($info['uid']) < 1 || intval($info['gid']) < 1 || intval($info['mUid']) < 1){
		        AC::$errorNo    =   'GRC001';
		        return FALSE;
		    }
		    // 圈子是否存在
		    $groupInfo  =   $this->groupInfoModel->groupAddRedis($info['gid']);
		    if (empty($groupInfo))
		    {
		    	AC::$errorNo = 'GRC012';
		    	return FALSE;
		    }
            $mUids = [];
		    if(!empty($groupInfo['mUids'])) {
                $mUids = explode(',', $groupInfo['mUids']);
            }
            // 只有圈子队长和管理员有权限
		    if($info['mUid'] != $groupInfo['uid'] && !in_array(intval($info['mUid']), $mUids)){
		    	AC::$errorNo = 'GRC014';
		    	return FALSE;
		    }

		    // 圈子队长和管理员不能被踢出
            if($info['uid'] == $groupInfo['uid'] || in_array(intval($info['uid']), $mUids)){
                AC::$errorNo = 'GRC028';
                return FALSE;
            }

		    $result =  $this->quitGroup($info);
		    if($result){
		        //加入被踢用户列表缓存
		        $this->diaryListCacheModel->addGroupBlackUser($info['gid'], $info['uid']);
            }
            return $result;
		}

        /**
         * 设为管理员
         * @param $info
         * @return bool|int|resource
         */
		private function giveUserManage($info){
		    if ( intval($info['mUid']) < 1 || intval($info['gid']) < 1 || intval($info['uid']) < 1){
		        AC::$errorNo    =   'GRC001';
		        return FALSE;
		    }
            $userInfo = $this->autoUidModel->getUserInfo($info['uid']);
            $mUserInfo = $this->autoUidModel->getUserInfo($info['mUid']);
            if(empty($userInfo) || empty($mUserInfo)){
                AC::$errorNo    =   'GRC041';           //用户信息错误
                return  FALSE;
            }
		    // 圈子是否存在
		    $groupInfo  =   $this->groupInfoModel->groupAddRedis($info['gid']);
		    if (empty($groupInfo))
		    {
		    	AC::$errorNo = 'GRC012';
		    	return FALSE;
		    }
            $mUids = array();
		    if(!empty($groupInfo['mUids'])){
                $mUids = explode(',', $groupInfo['mUids']);
            }
		    if($info['uid'] != $groupInfo['uid']){
		    	AC::$errorNo = 'GRC014';
		    	return FALSE;
		    }
		    $userGroupsInfo = $this->groupMembersModel->getUserGroupAllCache($info['mUid']);
		    $gids = isset($userGroupsInfo['gids']) ? $userGroupsInfo['gids'] : '';
		    if(empty($gids) || !in_array($groupInfo['gid'], explode(',', $gids))){
		    	AC::$errorNo = 'GRC015';  //成员不在圈子内
		    	return FALSE;
		    }
		    if(in_array($info['mUid'], $mUids)){
		    	AC::$errorNo = 'GRC017';  //成员已经是管理员了
		    	return FALSE;
		    }
		    if(count($mUids) >= AC::GROUP_MANAGE_USER_NUM){
		    	AC::$errorNo = 'GRC018';  //管理员数量已达上线
		    	return FALSE;
		    }
            if(!empty($userGroupsInfo['manageGid'])){
                $manageGroups = explode(',', $userGroupsInfo['manageGid']);
                if(count($manageGroups) >= AC::USER_MANAGE_GROUP_NUM) {
                    AC::$errorNo = 'GRC036';  //用户管理圈子数量已达到上限
                    return FALSE;
                }
            }
		    if(!empty($mUids)) {
                array_push($mUids, $info['mUid']);
                $mUids = implode(',', $mUids);
            } else {
                $mUids = $info['mUid'];
            }

		    $result = $this->groupInfoModel->editGroup(array('gid'=>$info['gid'], 'mUids'=>$mUids));
		    if($result) {
                $tmp = array('mUids'	=>	$mUids);
                $this->diaryListCacheModel->setGroupCache($info['gid'],$tmp);
                //设置完成更新用户圈子缓存
                if(isset($userGroupsInfo['manageGid']) && !empty($userGroupsInfo['manageGid'])) {
                    $data = [
                        'manageGid' => $userGroupsInfo['manageGid'] . ',' . $info['gid']
                    ];
                }else{
                    $data = [
                        'manageGid' => $info['gid']
                    ];
                }
                $this->diaryListCacheModel->addGroupUserCache($info['mUid'], $data);
                //私信通知
                $messageModel = new MessageBoxModel();
                $param = array(
                    'uid' => '1',
                    'mUid' => $info['mUid'],
                    'nickname' => '粉粉小秘书',
                    'mNickname' => $mUserInfo['nickname'],
                    'content' => $userInfo['nickname'] . '已将你设置为' . $groupInfo['name'] . '的管理员，快去圈子看看吧。',
                );
                $messageModel->sendAbilityMessage($param);
            }

		    if($result){
		        return true;
            }
            return false;
		}

        /**
         * 移除管理员
         * @param $info
         * @return bool|int|resource
         */
		public function removeManage($info){
            if (intval($info['mUid']) < 1 || intval($info['gid']) < 1 || intval($info['uid']) < 1){
                AC::$errorNo    =   'GRC001';
                return FALSE;
            }
            $userInfo = $this->autoUidModel->getUserInfo($info['uid']);
            $mUserInfo = $this->autoUidModel->getUserInfo($info['mUid']);
            if(empty($userInfo) || empty($mUserInfo)){
                AC::$errorNo    =   'GRC041';           //用户信息错误
                return  FALSE;
            }
            // 圈子是否存在
            $groupInfo  =   $this->groupInfoModel->groupAddRedis($info['gid']);
            if (empty($groupInfo))
            {
                AC::$errorNo = 'GRC012';
                return FALSE;
            }
            $mUids = array();
            if(!empty($groupInfo['mUids'])){
                $mUids = explode(',', $groupInfo['mUids']);
            }
            if($info['uid'] != $groupInfo['uid']){
                AC::$errorNo = 'GRC014';
                return FALSE;
            }
            $userGroupsInfo = $this->groupMembersModel->getUserGroupAllCache($info['mUid']);
            $gids = isset($userGroupsInfo['gids']) ? $userGroupsInfo['gids'] : '';
            if(empty($gids) || !in_array($groupInfo['gid'], explode(',', $gids))){
                AC::$errorNo = 'GRC015';  //成员不在圈子内
                return FALSE;
            }
            if(!in_array($info['mUid'], $mUids)){
                AC::$errorNo = 'GRC024';  //该用户不是管理员
                return FALSE;
            }

            $mUids = array_diff($mUids, array($info['mUid']));

            if(count($mUids) > 0) {
                $mUids = implode(',', $mUids);
            }else{
                $mUids = '';
            }

            $result = $this->groupInfoModel->editGroup(array('gid'=>$info['gid'], 'mUids'=>$mUids));
            if($result) {
                $tmp = array('mUids'	=>	$mUids);
                $this->diaryListCacheModel->setGroupCache($info['gid'],$tmp);
                //设置完成更新用户圈子缓存
                if(isset($userGroupsInfo['manageGid']) && !empty($userGroupsInfo['manageGid'])) {
                    $manageGid = explode(',', $userGroupsInfo['manageGid']);
                    $manageGid = array_diff($manageGid, array($info['gid']));
                    if(empty($manageGid)){
                        $data = ['manageGid' => ''];
                    }else{
                        $data = [
                            'manageGid' => implode(',', $manageGid)
                        ];
                    }
                    $this->diaryListCacheModel->addGroupUserCache($info['mUid'], $data);
                }
                //私信通知
                $messageModel = new MessageBoxModel();
                $param = array(
                    'uid' => '1',
                    'mUid' => $info['mUid'],
                    'nickname' => '粉粉小秘书',
                    'mNickname' => $mUserInfo['nickname'],
                    'content' => $userInfo['nickname'] . '已将你从' . $groupInfo['name'] . '的管理员中移除',
                );
                $messageModel->sendAbilityMessage($param);
            }

            if($result){
                return true;
            }
            return false;
        }

		/**
		 * 圈子转让
		 * @param unknown $info[gid] $info[uid]
		 * @return boolean|Ambigous <boolean, unknown>
		 */
		private function changeGroupUser($info){
		    if ( intval($info['tUid']) < 1 || intval($info['gid']) < 1 || intval($info['uid']) < 1){
		        AC::$errorNo    =   'GRC001';
		        return FALSE;
		    }
		    // 圈子是否存在
		    $groupInfo  =   $this->groupInfoModel->groupAddRedis($info['gid']);
		    if (empty($groupInfo))
		    {
		    	AC::$errorNo = 'GRC012';
		    	return FALSE;
		    }
		    // 队长才能转让
		    if($info['uid'] != $groupInfo['uid']){
		    	AC::$errorNo = 'GRC014';
		    	return FALSE;
		    }
            // 只能转让给管理员
            $mUids = array();
            if(!empty($groupInfo['mUids'])){
                $mUids = explode(',', $groupInfo['mUids']);
            }
            if(!in_array($info['tUid'], $mUids)){
                AC::$errorNo = 'GRC024';  //该用户不是管理员
                return FALSE;
            }

		    $result = $this->groupInfoModel->editGroup(array('gid'=>$info['gid'], 'uid'=>$info['tUid']));
            $tmp = array('uid'	=> $info['tUid']);
            $this->diaryListCacheModel->setGroupCache($info['gid'],$tmp);
		    return $result;
		}

        /**
         * 获取圈子成员
         * @param $info
         * @return array|bool
         */
		private function getGroupUser($info){
		    if (intval($info['gid']) < 1){
		        AC::$errorNo    =   'GRC001';
		        return FALSE;
		    }
		    $start = isset($info['start']) ? intval($info['start']) : 0;
		    $length = isset($info['length']) ? intval($info['length']) : 0;
		    // 圈子是否存在
		    $groupInfo  =   $this->groupInfoModel->groupAddRedis($info['gid']);
		    if (empty($groupInfo))
		    {
		    	AC::$errorNo = 'GRC012';
		    	return FALSE;
		    }
            $mUids = [];
		    if(!empty($groupInfo['mUids'])) {
                $mUids = explode(',', $groupInfo['mUids']);
            }
            // 圈子队长和管理员
            array_unshift($mUids, $groupInfo['uid']);

            $count = $groupInfo['member_num'] < 500 ? $groupInfo['member_num'] : 500;
		    $uids = $this->groupMembersModel->getGroupUsers($info['gid'], $start, $length, $count);
            if($uids) {             //去重
                $uids = array_diff($uids, $mUids);
            }

            if($start == 0) {        //队长及管理置顶
                $uids = array_merge($mUids, $uids);
            }
            $uids = array_unique($uids);
		    $result = ['user'=>[],'count'=>0];
		    if($uids){
		    	foreach ($uids as $uid) {
		    		$user = $this->autoUidModel->getUserInfo($uid);
		    		if(AC::$errorNo) AC::$errorNo = '';
		    		if(empty($user)) continue;
		    		$user['nickname'] = $this->autoUidModel->getRemarkName($user);
		    		$user['manage_level'] = 0;
		    		$uid == $groupInfo['uid'] && $user['manage_level'] = 1;   //创建人
                    if(in_array($uid, $mUids) && $user['manage_level'] == 0){
                        $user['manage_level'] = 2;                              //管理员
                    }
		    		$result['user'][] = $user;
		    	}
		    	$result['count'] = count($result['user']);
		    }
		    return $result;
		}
		
		/**
		 * 话题置顶/取消置顶/加精/取消加精
		 * @param unknown $info
		 * @return boolean
		 */
		private function stickTopic($info)/*{{{*/
		{
		    if (intval($info['tid']) < 1 || intval($info['gid']) < 1 || intval($info['uid']) < 1 || intval($info['opt']) < 1)
		    {
		        AC::$errorNo    =   'GRC001';
		        return  FALSE;
		    }
		    // 圈子是否存在
		    $groupInfo  =   $this->groupInfoModel->groupAddRedis($info['gid']);
		    if (empty($groupInfo))
		    {
		    	AC::$errorNo = 'GRC012';
		    	return FALSE;
		    }
		    //话题是否存在
		    $topicUser = $this->topicModel->topicAddRedis($info);
		    if (empty($topicUser) || intval($topicUser['gid']) != intval($groupInfo['gid']))
		    {
		        AC::$errorNo    =   'GRC008';
		        return  FALSE;
		    }
		    //判断是否有权限
            $mUids = array();
            if(!empty($groupInfo['mUids'])){
                $mUids = explode(',', $groupInfo['mUids']);
            }
		    if($info['uid'] != $groupInfo['uid'] && !in_array($info['uid'], $mUids)){
		    	AC::$errorNo = 'GRC014';
		    	return FALSE;
		    }
		    //置顶
		    if(intval($info['opt']) == 1){
		    	$info['display'] = 1;  
		    	//查询已经置顶的话题数
		    	$top_tids = json_decode($groupInfo['top_tids'], true);
		    	if(count($top_tids) >= AC::GROUP_TOP_TOPIC_NUM){
		    		AC::$errorNo = 'GRC019';  //置顶数已达上线
			    	return FALSE;
		    	}
		    }
		    intval($info['opt']) == 2 && $info['display'] = 0;  //取消置顶
		    intval($info['opt']) == 3 && $info['digest'] = 1;  //加精
		    intval($info['opt']) == 4 && $info['digest'] = 0;  //取消加精
		    $topic = $this->topicModel->stickTopicInfo($info);
		    if($topic && intval($info['opt']) == 1){
		        if(!empty($groupInfo['top_tids'])) {
                    $groupTop = json_decode($groupInfo['top_tids'], true);
                    array_unshift($groupTop, $info['tid']);
                }else{
                    $groupTop[] =  $info['tid'];
                }
		    	$this->groupInfoModel->editGroup(array('gid'=>$info['gid'],'top_tids'=>json_encode($groupTop)));
                //更新置顶缓存
                $tmp = array('top_tids'	=>	json_encode($groupTop));
                $this->diaryListCacheModel->setGroupCache($info['gid'],$tmp);
		    }
		    if($topic && intval($info['opt']) == 2){
		    	$groupTop = json_decode($groupInfo['top_tids'], true);
		    	$groupTop = array_diff($groupTop, [$info['tid']]);
		    	$this->groupInfoModel->editGroup(array('gid'=>$info['gid'],'top_tids'=>json_encode($groupTop)));
		    	//更新置顶缓存
                $tmp = array('top_tids'	=>	json_encode($groupTop));
                $this->diaryListCacheModel->setGroupCache($info['gid'],$tmp);
		    }
		    //更新话题信息缓存
		    if($topic) {
		        $this->diaryListCacheModel->delTopicInfo($info['tid']);
            }
		    return  $topic;
		}/*}}}*/
		
		/**
		 * 获取评论我的列表
		 * @param unknown $info
		 * @return boolean
		 */
		private function getCommentMeList($info){
		    if (intval($info['uid']) < 1 ){
		        AC::$errorNo    =   'GRC001';
		        return FALSE;
		    }
		    $result  =   $this->topicCommentsModel->getCommentMeList($info);
		    if (empty($result)){
		        return (Object) array();
		    }
		    $list  = array();
		    foreach ( $result as $commentFeed ){
	    		$extra    =    json_decode($commentFeed['extra_context'],true);
	    		if (intval($extra['gid']) < 1){
	    			continue;
	    		}
                $tmp['pid']    =    $extra['position'];
                $tmp['uid']    =    $commentFeed['authorUid'];
                $tmp['tid']    =    $commentFeed['tid'];
                $data = $this->groupInfoModel->groupAddRedis( $extra['gid'] );
                if (intval($data['status']) != 0){
                    continue;
                }
                if(intval($data['gid']) > AC::$groupMaxGid && $data['gtype'] != 1){
                    continue;
                }

                // 添加语音附件
                $attachment    =    $this->attachmentModel->getAttachmentInfo($tmp);
                $commentFeed['attachments'] =    $attachment['attachmentList'];
                $commentFeed['voiceList']   =    $attachment['voiceList'];
				
		        $tmp  =  $this->commentMeListData($commentFeed);
		        $list['comments'][] = $tmp;
		    }
		    $list['counts']    =    count($list['comments']);

		    // 重置话题轮询
		    $this->userStatisticsModel->resetNewTopicCommentTimesStatistics($info);
		    return $list;
		}
		
		/**
		 * 获取我的评论列表
		 * @param unknown $info
		 * @return boolean|StdClass|multitype:NULL
		 */
		private function getMyCommentsList($info){
			if (intval($info['uid']) < 1 ){
				AC::$errorNo    =   'GRC001';
				return FALSE;
			}
			// 是否是本人登录
			if ($info['uid'] != AC::HOST_UID){
				AC::$errorNo    =   'GRC005';
				return FALSE;
			}
			$result  =   $this->topicCommentsModel->getMyCommentsList($info);
			
			if (empty($result)){
				return (Object) array();
			}
			$list  = array();
			foreach ( $result as $commentFeed ){
				$extra    =    json_decode($commentFeed['extra_context'],true);
				$tmp['pid']    =    $extra['position'];
				$tmp['uid']    =    $commentFeed['uid'];
				if ($commentFeed['parentId'])
				{
					$tmp['uid']    =    $commentFeed['authorUid'];
				}
				$tmp['tid']    =    $commentFeed['tid'];
                if (intval($extra['gid']) < 1){
                    continue;
                }
                $data = $this->groupInfoModel->groupAddRedis( $extra['gid'] );
                if (intval($data['status']) != 0){
                    continue;
                }
                if(intval($data['gid']) > AC::$groupMaxGid && $data['gtype'] != 1){
                    continue;
                }

				// 添加语音附件
				$attachment    =    $this->attachmentModel->getAttachmentInfo($tmp);
				$commentFeed['attachments'] =    $attachment['attachmentList'];
				$commentFeed['voiceList']   =    $attachment['voiceList'];
				
				$tmp  =  $this->commentMeListData($commentFeed);
				$list['comments'][] = $tmp;
			}
			$list['counts']    =    count($list['comments']);
			
			return $list;
		}
		
		/**
		 * 将评论信息写入圈子动态
		 * 注:此处只写给被评论人
		 * @param unknown $info
		 * @return boolean|Ambigous <boolean, Ambigous, unknown>
		 */
		private function postCommentFeed($info){
		    if (intval($info['uid']) < 1 || intval($info['tid']) < 1 || intval($info['eUid']) < 1){
		        AC::$errorNo    =   'GRC001';
		        return FALSE;
		    }
		    // 通过redis获取话题系信息
		    $topic          =   $this->topicModel->topicAddRedis($info);
		    if (empty($topic)){
		        return FALSE;
		    }
		    // 从redis中查找圈子信息
		    $groupInfo      =   $this->groupInfoModel->groupAddRedis($topic['gid']);
		    if (empty($groupInfo)){
		        return FALSE;
		    }
		    $info['gname']  =   $groupInfo['name'];
		    $info['gid']    =   $groupInfo['gid'];
		    // 没有引用时将话题标题返回
		    if (intval($info['parentId']) < 1){
		        $info['extra']  =   $topic['title'];
		    }
		    
		    $result  =    $this->topicCommentsModel->postCommentFeed($info);
		    return $result;
		}
		
		/**
		 * 圈子评论入口
		 * @param unknown $info
		 * @return boolean|multitype:string multitype:string  multitype:multitype:string
		 */
		private function postTopicComment($info)/*{{{*/
		{
		    if (empty($info['tid']) || empty($info['uid']) || empty($info['author_uid']))
		    {
		        AC::$errorNo    =   'GRC001';
		        return  FALSE;
		    }
		    if ($info['uid'] != AC::HOST_UID)
		    {
		        AC::$errorNo    =   'GRC001';
		        return  FALSE;
		    }
		    // 是否禁言
		    $status  =  $this->autoUidModel->checkUserStatus(AC::$hostUserBaseInfo);
		    if (!empty(AC::$errorNo)){
		        return  FALSE;
		    }

            //是否被点滴/话题作者屏蔽
            $permissionService = new PermissionService();
            $shieldCheck = $permissionService->checkShieldUser($info['author_uid']);
            if (empty($shieldCheck)) return false;
            if($info['rUid'] != $info['author_uid']) {
                //是否被被评论人屏蔽
                $shieldCheck = $permissionService->checkShieldUser($info['rUid']);
                if (empty($shieldCheck)) return false;
            }
            //提前释放检测类，以免被其继承的析构函数影响到报错信息
            $permissionService = NULL;

		    // 评论间隔时间
		    $this->autoUidModel->checkUserSpace($info['uid']);
		    if (!empty(AC::$errorNo)) {
		        return  FALSE;
		    }
		    $result = $this->postComment($info);
		    $this->diaryListCacheModel->setCommentCheck($info['uid'], AC::SERVER_TIME);
		    
		    # 异步反垃圾分析
		    $classifyData = array(
		            'uid'         =>    strval($info['uid']),
		            'target'      =>    'topic_comment',
		            'targetId'    =>    strval($info['tid']),
		            'text'        =>    array(
		                    'title'	=>	'',
		                    'content'	=>	strval($info['content'])
		            ),
		            'attachments' =>	array(
		                    'images'	=>	$info['attachment'],
		                    'voices'	=>	$info['voice']
		            ),
		            'extra'       =>    array(
                    		    'gid'           =>    strval($result['comment_info']['gid']),
		                    'position'	    =>    strval($result['comment_info']['position']),
		                    'author_uid'    =>    strval($info['author_uid']),
		                    'rUid'          =>    strval($result['comment_info']['rUid']),
		                    'parentId'      =>    strval($result['comment_info']['parentId']),
		            ),
                    'version'     =>    AC::$antispam_version
		    );
		    $classifyDataOfJson = json_encode($classifyData);
		    RedisPool::addClassifyGearmanJob("classify", $classifyDataOfJson);
		    return $result;
		}/*}}}*/
		
		/**
		 * 对话题进行评论
		 * @param unknown $info
		 * @return boolean|multitype:string multitype:string  multitype:multitype:string
		 */
		private function postComment($info)/*{{{*/
		{
		    if (empty($info['tid']) || empty($info['uid']) || empty($info['author_uid']))
		    {
		        AC::$errorNo    =   'GRC001';
		        return  FALSE;
		    }
		    // 验证是否是本人登录
		    if ($info['uid'] != AC::HOST_UID){
		        AC::$errorNo    =   'GRC001';
		        return  FALSE;
		    }

		    // 被拉黑不能评论
		    $access =   $this->checkAccessPremission($info['author_uid']);
		    if (empty($access)) return  FALSE;
		    
		    // parentId判断加1
		    if (intval($info['parentId'])>0)
		    {
		        $info['parentId']	=	$info['parentId'] + 1;
                $commInfo['tid'] = $info['tid'];
                $commInfo['author_uid'] = $info['author_uid'];
                $commInfo['position'] = $info['parentId'];
                $comment = $this->topicCommentsModel->getCommentUid($commInfo);
                if(empty($comment) || $comment['status'] > 0) {
                    AC::$errorNo = 'GRC029';
                    return FALSE;
                }
		    }
		
		    // 获取用户信息
		    $info['nickname'] 		 =	AC::$hostUserBaseInfo['nickname'];
		    $authorUserInfo 	     =	$this->autoUidModel->getUserInfo($info['author_uid']);
		    if (!isset($authorUserInfo['nickname']))
		    {
		        AC::$errorNo    =   'GRC002';
		        return  FALSE;
		    }
		    $info['author_name']     =	$authorUserInfo['nickname'];
		    	
		    $info['rNickname']   	 =  '';
		    	
		    // 判断是否引用
		    if (intval($info['parentId']) > 0 && intval($info['rUid']) > 0) {
		        // 被拉黑不能评论
		        $access =   $this->checkAccessPremission($info['rUid']);
		        if (empty($access)) return  FALSE;
		        
		        $rUserInfo		 =  $this->autoUidModel->getUserInfo($info['rUid']);
		        if (!isset($rUserInfo['nickname'])) {
		            AC::$errorNo=   'GRC002';
		            return  FALSE;
		        }
		        $info['rNickname']   =   $rUserInfo['nickname'];
		    }
		
		    if (!isset($info['rNickname'])){
		        $info['rUid']      =  '0';
		        $info['parentId']  =  '0';
		    }
		
		    // 查找一次评论的话题是否存在
		    $topic = $this->topicModel->topicAddRedis($info);
		    if (empty($topic) || $topic['status'] > 0) {
		        AC::$errorNo=   'GRC002';
		        return FALSE;
		    }
		    // 圈子是否存在
		    $groupInfo = $this->groupInfoModel->groupAddRedis($topic['gid']);
		    if (empty($groupInfo) || $groupInfo['status'] > 0)
		    {
		    	AC::$errorNo = 'GRC012';
		    	return FALSE;
		    }
            // 圈子是否被封禁
            $this->diaryListCacheModel->deletePauseGroup();
            $pauseList = $this->diaryListCacheModel->getPauseGroupList();
            if(in_array($info['gid'], $pauseList)) {
                AC::$errorNo    =   'GRC032';   //圈子已被封禁，无法发布话题
                return FALSE;
            }
		    // 补话题gid，做统计用
		    $info['gid'] = $topic['gid'];
		    
		    // 匹配日记内容，找出匹配到的全部表情的id列表
		    $paper_emotion_ids_mebuy = array();
		    $matched_emotion_ids     = Emotion::matchEmotionIdList($info['content']);
		    $effective_ids           = $matched_emotion_ids;
		    if (empty(AC::$iosFullVersion)) {
    		    if ($matched_emotion_ids){
    		        // 获取我已购买的全部信纸、表情
    		        $paper_emotion_ids_mebuy = $this->shopModel->getShopIdListMeBuy($info['uid']);
    		    }
    		    $effective_ids       = array_intersect($paper_emotion_ids_mebuy, $matched_emotion_ids);
		    }
		    
		    // 以json格式存储到数据库中
		    if (is_array($effective_ids) && count($effective_ids) > 0){
		        $shop = array('shop_ids_mebuy' => $effective_ids);
		        $info['extend'] = json_encode($shop);
		    }

            // 如果是引用这获取被引用的内容组装返回接口以及加入动态
            $info['extra'] = '';
            if (intval($info['parentId']) > 0) {
                if(isset($info['positionId']) && intval($info['positionId']) > 0){
                    $childCommentInfo = $this->childCommentModel->getCommentInfo(AC::COMMENT_TYPE_GROUP, $info['tid'], $info['positionId']);
                    if(empty($childCommentInfo)) {
                        AC::$errorNo = 'GRC029';
                        return FALSE;
                    }
                    $info['extra_uid'] = isset($childCommentInfo['rUid']) ? $childCommentInfo['rUid'] : 0;
                    $info['extra_nickname'] = isset($childCommentInfo['rNickname']) ? $childCommentInfo['rNickname'] : '';
                    // 判断评论内容是否大于50个字,大于则加上省略号
                    $info['extra'] = UK::getstr($childCommentInfo['content'], '100', '...', 1);
                    unset($info['positionId']);
                }else{
                    $info['extra_uid'] = isset($comment['rUid']) ? $comment['rUid'] : 0;
                    $info['extra_nickname'] = isset($comment['rNickname']) ? $comment['rNickname'] : '';
                    // 判断评论内容是否大于50个字,大于则加上省略号
                    $info['extra'] = UK::getstr($comment['content'], '100', '...', 1);
                }
            }
            $info['content'] = UK::getstr($info['content'], AC::TOPIC_BODY_LENGTH,'',0);

            $check = UK::checkVersion('5.71', '5.7.1');

            // 3.写评论表(没有父id或者是低版本则不适用楼中楼)
            if(intval($info['parentId']) == 0 || $check) {

                $commentId = $this->topicCommentsModel->postTopicComment($info);
                if (!empty(AC::$errorNo)) {
                    return FALSE;
                }

                // 添加附件
                $info['commentId'] = $commentId;
                $this->addAttachment($info);

                // 增加话题评论数以及最后回复时间,楼主发帖时评论数不改变
                if ($commentId > 1) {
                    // 加入redis
                    $this->topicChangeNum($info);
                }

                // 获取刚刚评论的信息然后返回
                $info['position'] = $commentId;
                $info['status'] = '0';
                $info['time'] = AC::SERVER_TIME;
                $result['comment_info'] = $this->commentsData($info);
            } else {
                $info['type'] = AC::COMMENT_TYPE_GROUP;
                $info['typeId'] = $info['tid'];
                $commentId = $this->childCommentModel->addComment($info);
                if (empty($commentId)) return false;

                $info['position'] = $info['parentId'];
                $info['positionId'] = $commentId;

                //新评论更新父评论的被评论数，如果数量小于3 则要更新附加字段的信息
                if($commentId){
                    $this->updateParentComment($info['parentId'], $info['tid'], $info['author_uid'], $info);
                }

                $comment = $this->childCommentModel->getCommentInfo(AC::COMMENT_TYPE_GROUP, $info['tid'], $commentId);
                $result['comment_info'] = $this->rebuildChildCommentData($comment, $info['author_uid']);
                if (!empty(AC::$errorNo)) {
                    return FALSE;
                }
                $this->topicChangeLastTime($info);
                //此处赋值是为放入动态时楼层数为主楼层
                $commentId = $info['parentId'];
            }
            // 更新今日新增话题数
            $this->addTodayGroupTopicNum($topic['gid'], $groupInfo['today']);
            // 最后回复话题进缓存
            $data = array('l_tid' => $info['tid']);
            $this->diaryListCacheModel->setGroupNodbCache($topic['gid'], $data);
		    // 写入圈子动态
		    $feedInfo   =   array(
		            'uid'               =>  intval($info['rUid']) > 0 ? intval($info['rUid']) : $info['author_uid'],
		            'eUid'              =>  $info['uid'],
		            'eNickname'         =>  $info['nickname'],
		            'authorUid'         =>  $info['author_uid'],
		            'authorNickname'    =>  $info['author_name'],
		            'tid'               =>  $info['tid'],
		            'position'          =>  $commentId,
		            'parentId'          =>  $info['parentId'],
		            'positionId'        =>  isset($info['positionId']) ? $info['positionId'] : 0,
		            'type'              =>  '1',
		            'content'           =>  $info['content'],
		            'extra'             =>  $info['extra'],
		            'extra_uid'         =>  $info['extra_uid'],
                    'extra_nickname'    =>  $info['extra_nickname'],
		            'action'            =>  'postCommentFeed',
		    );
            $commentCheck = false;
		    if(empty($info['rUid']) && $info['uid'] != $info['author_uid']){
		        $commentCheck = true;               //没有rUid判断是否楼主自己回复自己
            }
            if(!empty($info['rUid']) && $info['uid'] != $info['rUid']){
                $commentCheck = true;               //有rUid判断是否自己回复自己
            }
		    if ($commentCheck){
		        // 轮询&加入动态
		        AC::$userStatistics[$feedInfo['uid']]['newTopicComment']=   1;
		        $this->postCommentFeed($feedInfo);
		    }
		    // 推送
		    $push	=	new PushController();
		    $push->push($info, "pushTopicComment");
		    
		    return  $result;
		}/*}}}*/

        /**
         * 添加子评论时更新父评论的附加字段
         * @param $parentId
         * @param $tid
         * @param $author_uid
         * @param $param
         * @return bool
         */
        private function updateParentComment($parentId, $tid, $author_uid, $param){
            if (empty($parentId) || empty($tid) || empty($author_uid) ) return false;

            $parentComment = $this->topicCommentsModel->getCommentInfo($parentId, $tid, $author_uid);
            if ($parentComment) $parentComment['parentId'] = 0;

            if(empty($parentComment)){
                return true;
            }

            $info = [
                'position'  =>  $parentId,
                'tid'       =>  $tid,
                'author_uid'=>  $author_uid
            ];
            $extend = UK::parseData($parentComment['extend']);
            if($extend['commentTimes'] >= 3) {
                $extend['commentTimes'] = $extend['commentTimes'] + 1;
            } else {
                $extend['childComment'][] = [
                    "uid"           => $param['uid'],
                    'position'      =>  $parentId,
                    'positionId'    =>  $param['positionId'],
                    'nickname'      =>  $param['nickname'],
                    "created_at"    => AC::SERVER_TIME,
                    "content"       => $param['content']
                ];
                $extend['commentTimes'] = $extend['commentTimes'] + 1;
            }

            $info['extend'] = UK::var_json_encode($extend);
            return $this->topicCommentsModel->updateTopicComment($info);
        }

        /**
         * 删除子评论时更新父评论附加字段
         * @param $position
         * @param $tid
         * @param $author_uid
         * @param $childCommentList
         * @return bool|int|resource
         */
        public function updateParentCommentExtend($position, $tid, $author_uid, $childCommentList) {
            $info = [
                'position'  =>  $position,
                'tid'       =>  $tid,
                'author_uid'=>  $author_uid
            ];
            if(empty($childCommentList)) {
                $info['extend'] = '';
                return $this->topicCommentsModel->updateTopicComment($info);
            } else {
                $count = count($childCommentList);
                $commentList = array_slice($childCommentList, 0, 3);
                foreach ($commentList as $value) {
                    $extend['childComment'][] = [
                        "uid"           =>  $value['uid'],
                        'position'      =>  $value['parentId'],
                        'positionId'    =>  $value['position'],
                        'nickname'      =>  $value['nickname'],
                        "created_at"    =>  $value['created_at'],
                        "content"       =>  $value['content']
                    ];
                }
                $extend['commentTimes'] = $count;
                $info['extend'] = UK::var_json_encode($extend);
                return $this->topicCommentsModel->updateTopicComment($info);
            }
        }

        //循环格式化子评论数据
        private function loopDataOfChildComment($param, $author_uid){
            if (empty($param)) return array();

            $result = array();
            foreach ($param as $value) {
                if (empty($value['uid'])) continue;
                $childComment = $this->rebuildChildCommentData($value, $author_uid);
                $result[] = $childComment;
            }

            return $result;
        }

        /**
         * 组装子评论结构
         * @param $info
         * @param $author_uid
         * @return array
         */
        private function rebuildChildCommentData($info, $author_uid){
            if ($info['status'] > 0) $info['content'] = '该评论已被删除';
            $result = [
                "tid"           =>  $info['typeId'],
                "author_uid"    =>  $author_uid,
                "uid"           =>  $info['uid'],
                'position'      =>  $info['parentId'] - 1,          //父评论所在楼层
                'positionId'    =>  $info['position'],             //该评论的标示
                'nickname'      =>  $info['nickname'],
                "created_at"    =>  $info['created_at'],
                "content"       =>  $info['content'],
                "user"          =>  $this->autoUidModel->getUserInfo($info['uid'])
            ];
            return $result;
        }

        /**
         * 发布话题
         * @param $info
         * @return bool
         */
		public function addTopic($info)/*{{{*/
		{
		    $uid = AC::HOST_UID;
		    $topicBodyLength = AC::TOPIC_BODY_LENGTH;
		    $topicTitleLength = AC::TOPIC_TITLE_LENGTH;
		    $info['content']	=	UK::getstr($info['content'], $topicBodyLength);
		    $info['title']	    =   UK::getstr($info['title'], $topicTitleLength,'',1);
		    if (strlen($info['title']) < 2 || strlen($info['content']) < 1 || empty($uid)) {
		        AC::$errorNo    =   'TPM001';
		        return  FALSE;
		    }
		    // 是否禁言
		    $userInfo =  $this->autoUidModel->getUserInfo($info['uid'], TRUE);
		    $status  =  $this->autoUidModel->checkUserStatus($userInfo);
		    if (!$status || !empty(AC::$errorNo)){
		        return  FALSE;
		    }
		    // 圈子是否存在
		    $groupInfo  =   $this->groupInfoModel->groupAddRedis($info['gid']);
		    if (empty($groupInfo)) {
		    	AC::$errorNo = 'GRC012';
		    	return FALSE;
		    }
		    // 圈子是否被封禁
            $this->diaryListCacheModel->deletePauseGroup();
            $pauseList = $this->diaryListCacheModel->getPauseGroupList();
            if(in_array($info['gid'], $pauseList)) {
                AC::$errorNo    =   'GRC032';   //圈子已被封禁，无法发布话题
                return FALSE;
            }
		    
		    if (empty($info['uid'])  ||  empty($info['gid']))
		    {
		        AC::$errorNo    =   'GRC001';
		        return  FALSE;
		    }

		    //用户未加入则不能发布话题
            $userGroups     = $this->groupMembersModel->getUserGroupAllCache($info['uid']);
            $userGroupCache = $this->checkUserInitGroupsOrmUids($info['uid'], $userGroups);
            $gids = array();
            if ($userGroupCache['gids']) {
                $gids =  $userGroupCache['gids'];
            }
            if (!in_array($info['gid'], $gids) && $groupInfo['uid'] != $info['uid']){
                AC::$errorNo    =   'GRC004';
                return FALSE;
            }
		    
		    // 判别是否重复提交
		    $ck = md5($info['content']);
		    $lastCk = $this->diaryListCacheModel->getLastCheckConnentOfTopic($info['uid']);
		    if($lastCk && $lastCk==$ck)
		    {
		        AC::$errorNo    =   'GRC013';
		        return  FALSE;
		    }
		    $this->diaryListCacheModel->setLastCheckConnentOfTopic($info['uid'], $ck);
		    	
		    // 话题间隔时间
		    $this->autoUidModel->checkUserSpace($info['uid']);
		    if (!empty(AC::$errorNo) ) {
		        return  FALSE;
		    }
		    
		    // 投票基本过滤
		    $vote = $this->voteModel->filterTopicVote($info['vote']);
		    if (AC::$errorNo) {
		        UK::varDump(AC::$errorNo, __METHOD__);
		        return  FALSE;
		    }
		    
		    $info['vote'] = $vote ? 1 : 0;
		    $topicId    =   $this->topicModel->addTopic($info);
	        
		    // 投票
		    $voteInfo = array('uid' => AC::HOST_UID, 'tid' => $topicId, 'vote' => $vote);
		    if($vote){
		        $voteLinkId = $this->voteModel->addVoteLink($uid, $topicId, $vote);
		        if ($voteLinkId) {
		            $voteOptionsId = $this->voteModel->addVoteOptions($uid, $topicId, $vote, $voteLinkId);
		        }
		    }
		    
		    if (AC::$errorNo) {
		        UK::varDump(AC::$errorNo, __METHOD__);
		        return  FALSE;
		    }
		    // 设置当前时间
		    $this->diaryListCacheModel->setCommentCheck($info['uid'], AC::SERVER_TIME);
		    // 评论结构 start 
		    $info['tid']		     =	$topicId;
		    $info['author_uid']	     =	$info['uid'];
		    $info['nickname'] 		 =	$userInfo['nickname'];
		    $info['author_name'] 	 =	$userInfo['nickname'];
		    
		    // 匹配日记内容，找出匹配到的全部表情的id列表
		    $paper_emotion_ids_mebuy = array();
		    $matched_emotion_ids     = Emotion::matchEmotionIdList($info['content']);
		    $effective_ids           = $matched_emotion_ids;
		    if (empty(AC::$iosFullVersion)) {
		        if ($matched_emotion_ids){
		            // 获取我已购买的全部信纸、表情
		            $paper_emotion_ids_mebuy = $this->shopModel->getShopIdListMeBuy($info['uid']);
		        }
		        $effective_ids       = array_intersect($paper_emotion_ids_mebuy, $matched_emotion_ids);
		    }
		    
		    // 以json格式存储到数据库中
		    if (is_array($effective_ids) && count($effective_ids) > 0){
		        $shop = array('shop_ids_mebuy' => $effective_ids);
		        $info['extend'] = json_encode($shop);
		    }
		    
		    // end
		    $commentId =   $this->topicCommentsModel->postTopicComment($info);
		    if (!empty(AC::$errorNo)){
		        return FALSE;
		    }
		    if (empty($commentId))
		    {
		        AC::$errorNo    =   'GRC006';
		        return  FALSE;
		    }
		    // 添加附件
		    $info['commentId']    =    $commentId;
		    $this->addAttachment($info);
		    
		    // redis中圈子话题数自增 
		    $this->groupTopicNum($info);
		    $num = $this->groupInfoModel->addTopicNum(array('gid'=>$info['gid']), 1);
		    if (empty($num))
		    {
		        AC::$errorNo    =   'GRC006';
		        return  FALSE;
		    }
		    // 今日新增话题数
		    $this->addTodayGroupTopicNum($info['gid'], $groupInfo['today']);
		    // 最后回复话题进缓存
		    $data = array('l_tid'	=>	$topicId);
		    $this->diaryListCacheModel->setGroupNodbCache($info['gid'], $data);
		    // 用户话题数自增
		    AC::$userStatistics[$info['uid']]['topicTimes']  =   1;
		    $topicInfo = $this->getTopicInfo(array('tid'=>$topicId));
		    // 圈子排序增加
            $this->groupInfoModel->addGroupToCategory($info['gid']);
		    
		    // 达人升级
		    $this->autoUidModel->updateAbilityLevel($info['uid']);
		    
		    // 异步反垃圾分析
		    $classifyData = array(
		            'uid'         =>    strval($info['uid']),
		            'target'      =>    'topic',
		            'targetId'    =>    strval($topicId),
		            'text'        =>    array(
		                    'title'	    =>	strval($info['title']),
		                    'content'	=>	strval($info['content'])
		            ),
		            'attachments' =>	array(
		                    'images'	=>	$info['attachment'],
		                    'voices'	=>	$info['voice']
		            ),
		            'extra'       =>    array(
		                    'gid'	        =>    strval($info['gid']),
		                    'author_uid'    =>    strval($info['uid'])
		            ),
                    'version'     =>    AC::$antispam_version
		    );
		    
		    $classifyDataOfJson = json_encode($classifyData);
		    RedisPool::addClassifyGearmanJob("classify", $classifyDataOfJson);
		    
		    // 话题进日记
		    $this->topicIntoDiary($topicInfo, $topicInfo['topic_info']['uid']);
		    if(AC::$errorNo){
		    	AC::$errorNo = NULL;
		    }
		    
		    return  $topicInfo;
		}/*}}}*/

		/**
		 * 用户投票
		 * @param unknown $info
		 * @return boolean
		 */
		public function voteTopic($info){
			// init params
			isset($info['uid'])           &&    $host_id  =    intval($info['uid']);
			isset($info['tid'])           &&    $tid      =    intval($info['tid']);
			isset($info['voteids'])       &&    $oid      =    $info['voteids'];
			// check params
			if ($host_id < 1 || $tid < 1){
				AC::$errorNo    =   'GRC001';
				return false;
			}

			// 是否是本人登录
			if ($host_id != AC::HOST_UID){
				AC::$errorNo    =   'GRC005';
				return false;
			}

			//获取话题信息 并判断话题是否存在
			$topic = $this->topicModel->topicAddRedis(array('tid' => $tid));
			if(empty($topic)){
				AC::$errorNo = 'GRC002';
				return false;
			}

			//检测是否添加投票
			if($topic['vote'] == 0){
				AC::$errorNo = 'GRC009';
				return false;
			}
			//初始化传参条件
			$author_uid = $topic['uid'];

			//获取投票表信息
			$voteLinkInfo = $this ->voteModel->getVoteLinkInfo($tid);
			if(empty($voteLinkInfo) || $voteLinkInfo['status'] == 2){
				AC::$errorNo = 'GRC010';
				return false;
			}

			//判断选项是否超出最大选大选项
			$max_options = count($oid);
			if($voteLinkInfo['max_options'] < $max_options){
				AC::$errorNo = 'GRC005';
				return false;
			}

			//获取选项表信息
			$voteOptionsInfo = $this->voteModel->getVoteOptions($tid,$author_uid, $host_id);
			//数据拆分
			$isvoted = $voteOptionsInfo['isvoted'];
			$vid = $voteLinkInfo['id'];
			$list = $voteOptionsInfo['list'];
			if($isvoted){
				AC::$errorNo    =   'GRC006';
				return false;
			}
			//添加投票
			$result = $this->voteModel->addTopicVoteLogs($oid,$host_id,$author_uid,$tid, $vid);
			return $result;
		}


		/**************************************************************/
		/**
		 * 话题进日记
		 * @param unknown $topicInfo
		 * @param unknown $uid
		 * @return boolean|multitype:Ambigous <> |Ambigous <string, unknown, boolean, number>
		 */
		public function topicIntoDiary($topicInfo, $uid){
		    // 获取用户详情
		    $userInfo = $this->autoUidModel->getUserInfo($uid);
		    if (empty($userInfo)){
		        return FALSE;
		    }
		    
		    // 数据组装
		    $topic = $topicInfo['topic_info'];
			$diaryData = array(
			        'uid'    =>    $uid,
			        'nickname' =>  $userInfo['nickname'],
			        'title'  =>    $topic['title'],
			        'content'=>    $topic['content']
			);
			$tmp = array(
			        'url_type'         =>    'topic',
			        'url_type_id'      =>    $topic['tid'],
			        'url_type_uid'     =>    $uid,
			);
			$diaryData['extras']['topic'][]	=	$tmp;
			$diaryData['extras']            =   json_encode($diaryData['extras']);

			// 附件数据结构
			$attachment = $tmp = array();
			if (is_array($topic['attachments']) && count($topic['attachments']) > 0){
			    foreach ($topic['attachments'] as $value){
			        $tmp['info'] = $value['info'];
			        $tmp['type'] = $value['attachmentType'];
			        $tmp['path'] = $value['attachmentPath'];
			        $attachment[] = $tmp;
			    }
			}
			
			// 入库
			$diaryId    =   $this->diaryBodyModel->addDiaryBody($diaryData);
			if (empty($diaryId)){
			    UK::varDump(AC::$errorNo, __METHOD__);
			    return  FALSE;
			}
			
			$diaryData['bodyId']=   $this->diaryBodyModel->getBodyId($diaryData['uid'], $diaryId);
			if (empty($diaryData['bodyId']))
			{
			    UK::varDump(AC::$errorNo, __METHOD__);
			    return  FALSE;
			}
			
			// 默认为图片附件
			if (is_array($attachment)  &&  count($attachment) >   0)
			{
				foreach ($attachment as $value){
					$attachments[] = $value['path'];
				}
				$diaryData['attachment'] = $attachments;
				$tmpInfo    =   array(
				    'uid'               =>  $diaryData['uid'],
				    'bodyId'            =>  $diaryData['bodyId'],
				    'attachment'        =>  $attachments,
				    'attachment_type'   =>  1,
				    'type'              =>  1,
				    'type_id'           =>  $diaryData['bodyId'],
				);
			    
				$this->diaryAttachmentModel->addDiaryAttachment($tmpInfo);
			}
			
			$diaryListInsert=   $this->diaryListModel->addDiaryList($diaryData);
			if (empty($diaryListInsert))
			{
	    			UK::varDump(AC::$errorNo, __METHOD__);
	    			return  FALSE;
			}
			
			$result =   array('bodyId' => $diaryData['bodyId']);
			//将日志加入redis缓存
			$this->diaryListModel->getDiaryInfoByBodyId($diaryData['bodyId']);
			if (!empty($diaryData['secret'])){
				AC::$userStatistics[$diaryData['uid']]['secretDiaryTimes']  =   1;
				return  $result;
			}
			$this->diaryListCacheModel->addUserTimeline($diaryData['uid'], $diaryData['bodyId']);
			#  feed & statistics    /*{{{*/
			AC::$userStatistics[$diaryData['uid']]['diaryTimes']    =   1;
			AC::$feedInfo   =   array(
			        'uid'               =>  $diaryData['uid'],
			        'eUid'              =>  $diaryData['uid'],
			        'eNickname'         =>  $diaryData['nickname'],
			        'authorUid'         =>  $diaryData['uid'],
			        'authorNickname'    =>  $diaryData['nickname'],
			        'bodyId'            =>  $diaryData['bodyId'],
			        'type'              =>  AC::FEED_DIARY,
			        'label'             =>   (isset($diaryData['label']) && intval($diaryData['label']) > 0 && intval($diaryData['label']) <= AC::DIARY_TAG_MAXID) ? intval($diaryData['label']) : 0
			);
			
			strlen($diaryData['content']) > 0    &&  AC::$feedInfo['content']    =   $diaryData['content'];
			strlen($diaryData['title']) > 0      &&  AC::$feedInfo['content']    =   $diaryData['title'];
			strlen(AC::$feedInfo['content']) < 1 &&  AC::$feedInfo['content']    =   ' write Diary, No title ? No content ? ! ';

			return $diaryData;
		}
		
		#对组的操作
		/**
		 * 创建圈子
		 * @param unknown $info
		 * @return boolean|Ambigous <multitype:, boolean, unknown>
		 */
		public function createGroup($info)/*{{{*/
		{
		    if (empty($info['uid'])) {
		        AC::$errorNo    =   'GRC001';
		        return  FALSE;
		    }
		    // 加入到分类信息中
		    if (intval($info['category']) < 1){
                AC::$errorNo    =   'GRC035';           //未选择分类
                return  FALSE;
		    }
		    $userInfo = $this->autoUidModel->getUserInfo($info['uid']);
		    if(empty($userInfo)){
                AC::$errorNo    =   'GRC041';           //用户信息错误
                return  FALSE;
            }
            if($userInfo['is_ability'] != 1){
                AC::$errorNo    =   'GRC042';           //非达人不能创建
                return  FALSE;
            }

		    //查询创建圈子数量
		    $createCount = $this->groupInfoModel->getCreatedGroupNum($info);
            $userGroupsInfo = $this->groupMembersModel->getUserGroupAllCache($info['uid']);

		    if($createCount >= AC::USER_CREATE_GROUP_NUM){
		    	AC::$errorNo    =   'GRC033';
		        return  FALSE;
		    }

		    if(empty($info['avatar']) || empty($info['cover'])){
                AC::$errorNo    =   'GRM003';           //封面和头像必须有
                return  FALSE;
            }
		    if($info['avatar']) {
		        $info['extras'] = json_encode(['avatar'=>$info['avatar']]);
            }
		    $groupId = $this->groupInfoModel->createGroup($info);
		    if (empty($groupId)){
		    	return  FALSE;
		    }
		    // 创建完成插入创建人入小组成员中
		    $info['gid']    =    $groupId;
		    $info['gtype']  =    1;
		    $this->groupMembersModel->addMembers($info);
		    //创建完成更新用户圈子的缓存
            if(isset($userGroupsInfo['createGid']) && !empty($userGroupsInfo['createGid'])) {
                $data = [
                    'createGid' => $userGroupsInfo['createGid'] . ',' . $groupId
                ];
            }else{
                $data = [
                    'createGid' => $groupId
                ];
            }
            $this->diaryListCacheModel->addGroupUserCache($info['uid'], $data);
            //更新该分类下圈子列表缓存
            $this->groupInfoModel->addGroupToCategory($groupId);
		    // 返回小组详情
		    $groupInfo = $this->getGroupInfo($info);
		    return  $groupInfo;
		}/*}}}*/		
		// 我加入的圈子
		public function getGroupMeList($info)/*{{{*/
		{
		    if (intval($info['uid']) < 1){
		    	AC::$errorNo    =   'GRC001';
		        return FALSE;
		    }
            $userInfo = $this->autoUidModel->getUserInfo($info['uid']);
            if(empty($userInfo)){
                AC::$errorNo    =   'GRC041';           //用户信息错误
                return  FALSE;
            }

		    // 获取用户关注的圈子列表情况
		    $userGroups     = $this->groupMembersModel->getUserGroupAllCache($info['uid']);
		    // 判断是否初始化关注圈子及关注管理员
		    $userGroupCache = $this->checkUserInitGroupsOrmUids($info['uid'], $userGroups);
		    $gids = array();
		    if ($userGroupCache['gids']) {
		        $gids =  $userGroupCache['gids'];
		    }
		    if (empty($gids)){
		    	return (Object) array();
		    }
		    
		    // 重置轮询
		    $this->userStatisticsModel->resetNewTopicMessageTimesStatistics($info);

            $userGroupsInfo = $this->groupMembersModel->getUserGroupAllCache($info['uid']);
            $topGid = $createGid = array();
            if(isset($userGroupsInfo['createGid']) && !empty($userGroupsInfo['createGid'])) {
                $createGid = explode(',',$userGroupsInfo['createGid']);
            }
            if(isset($userGroupsInfo['topGid']) && !empty($userGroupsInfo['topGid'])) {
                $topGid = explode(',',$userGroupsInfo['topGid']);
            }
            //置顶圈子+创建圈子+加入的圈子+分页
            $userGids = array_unique(array_merge($createGid, $gids));
            $userGids = array_diff($userGids, $topGid);
            $userGids = array_merge($topGid, $userGids);

            //创建数量验证
            $createCount = $this->groupInfoModel->getCreatedGroupNum($info);

            $createCheck = 0;
            if($userInfo['is_ability'] == 1 && $createCount < AC::USER_CREATE_GROUP_NUM){
                $createCheck = 1;
            }

            $start = 0;
            $length = 20;
            if(array_search($info['gid'], $userGids)) $start = array_search($info['gid'], $userGids) + 1;
            isset($info['length']) && $length =  $info['length'];
            $result = array_slice($userGids, $start, $length);

			$data = array();
			foreach ($result as $value)
			{
				// 从redis中查找圈子信息
				$groupInfo   =   $this->groupInfoModel->groupAddRedis($value);
				if (empty($groupInfo)) {
					continue;
				}

				$tmp				=	$this->groupData($groupInfo, $gids);
				$tmp['new_topic'] 	= 	$this->getLastestTopics($groupInfo);
				$data['groups'][] 	= 	$tmp;
			}
			$data['counts'] = count($data['groups']);
			$data['createCheck'] = $createCheck;
			$data['userCache'] = $userGroups;
			return $data;
		}/*}}}*/
		// 我创建的圈子
		public function getGroupMeCreate($info)/*{{{*/
		{
		    if (intval($info['uid']) < 1){
		    	AC::$errorNo    =   'GRC001';
		        return FALSE;
		    }
		    // 获取我创建的圈子列表情况
		    $userGroups     = $this->groupInfoModel->getMeCreateGroup($info);
		    if (empty($userGroups)){
		    	return (Object) array();
		    }
		    
		    // 重置轮询
		    $this->userStatisticsModel->resetNewTopicMessageTimesStatistics($info);

			$data = array();
			foreach ($userGroups as $value)
			{
				// 从redis中查找圈子信息
				$groupInfo   =   $this->groupInfoModel->groupAddRedis($value['gid']);
				if (empty($groupInfo)) {
					continue;
				}
				$tmp				=	$this->groupData($groupInfo, $value['gid']);
				$tmp['new_topic'] 	= 	$this->getLastestTopics($groupInfo);
				$data['groups'][] 	= 	$tmp;
			}
			$data['counts'] = count($data['groups']);
			return $data;
		}/*}}}*/	
		// 获取最新话题
		private function getLastestTopics($groupInfo){
			if (empty($groupInfo['gid'])) {
				return array();
			}
			
			$result = array();
			if (!empty($groupInfo['l_tid'])){
				$result = $this->topicModel->topicAddRedis(array('tid'=>$groupInfo['l_tid']));
			}
			
			// 判断缓存(话题删除或者缓存中没有l_tid)
			if (empty($result) || empty($groupInfo['l_tid'])){
				// 取数据库
				$topic 		= $this->topicModel->getTopicList(array('gid'=>$groupInfo['gid'],'length'=>1,'new_topic'=>0,'no_display'=>1));
				$result 	= $topic[0];
				
				// 更新缓存
				$tmp = array('l_tid'	=>	$result['tid']);
				$this->diaryListCacheModel->setGroupCache($groupInfo['gid'], $tmp);
			}
			
			// 数据结构化
            if(!empty($result)) {
                $list['topics'][0]  =   $this->topicData($result,1);
            } else {
                $list['topics'] = array();
            }

			$list['counts']		=	count($list['topics']);
			return $list;
		}	
		#编辑组信息
		public function editGroup($info)/*{{{*/
		{
			if (empty($info['gid']))
			{
				AC::$errorNo    =   'GRC001';
				return  FALSE;
			}
			#小组名10个字
            $groupNameLength = AC::GROUP_NAME_LENGTH;
			$info['name']       	 =	UK::getstr($info['name'], $groupNameLength,'',1);
			#小组介绍200个字
            $groupIntroLength = AC::GROUP_INTRO_LENGTH;
			$info['introduction']    =	UK::getstr($info['introduction'], $groupIntroLength,'',1);
			
			if (isset($info['introduction'])  &&  strlen($info['introduction']) < 1){
			    unset($info['introduction']);
			}
			if (isset($info['cover'])          &&  empty($info['cover'])){
			    unset($info['cover']);
			}
			if (isset($info['name'])           &&  strlen($info['name']) < 1){
			    unset($info['name']);
			}
            $groupInfo = $this->groupInfoModel->getGroupInfo($info);
			if(empty($groupInfo)) {
			    AC::$errorNo = 'GRC012';
			    return false;
            }
            if(isset($info['name']) && $info['name'] == $groupInfo['name']) {
                unset($info['name']);
            }
            if(isset($info['category']) && $info['category'] == $groupInfo['category']) {
                unset($info['category']);
            }
            $extraInfo = UK::parseData($groupInfo['extras']);
            if($info['avatar']) {
                $extraInfo['avatar'] = $info['avatar'];
                $info['extras'] = UK::var_json_encode($extraInfo);
            }
			
			$this->groupInfoModel->editGroup($info);
			if (AC::$errorNo)
			{
				UK::varDump(AC::$errorNo, __METHOD__);
				return  FALSE;
			}
			// 清除缓存
			$this->diaryListCacheModel->delGroupCache($info['gid']);
			if($info['category'] != $groupInfo['category']){
                $this->diaryListCacheModel->remGroupByCategory($groupInfo['category'], $groupInfo['gid']);
            }

			//更新分类下圈子列表缓存
            $this->groupInfoModel->addGroupToCategory($info['gid']);
			return TRUE;
		}/*}}}*/		
		#解散组
		public function removeGroup($info)/*{{{*/
		{
			if (empty($info['gid']) || empty($info['uid']))
			{
				AC::$errorNo    =   'GRC001';
				return FALSE;
			}
            $groupInfo = $this->groupInfoModel->groupAddRedis($info['gid']);
			if(empty($groupInfo)){
                AC::$errorNo = 'GRC012';
                return  FALSE;
            }
			
			# access FALSE不是小组创建者无权解散
			$access = $this->createrCanDo($info);
			if (AC::$errorNo || empty($access))
			{
				UK::varDump(AC::$errorNo, __METHOD__);
				return  FALSE;
			}
			
			$result = $this->groupInfoModel->removeGroup($info);
			if (empty($result))
			{
				AC::$errorNo = 'GRC007';
	            return  FALSE;
			}
			$this->diaryListCacheModel->delGroupCache($info['gid']);
			return TRUE;
		}/*}}}*/		
		#单个组信息
		public function getGroupInfo($info)/*{{{*/
		{
		    if (intval($info['gid']) < 1){
		        AC::$errorNo = 'GRC001';
		        return FALSE;
		    }
		    // 从redis中查找圈子信息
			$result  		=   $this->groupInfoModel->groupAddRedis($info['gid']);
			$userGroups     = 	$this->groupMembersModel->getUserGroupAllCache(AC::HOST_UID);
			$userGroupCache =   $this->checkUserInitGroupsOrmUids(AC::HOST_UID, $userGroups);
			if (empty($result)) {
			    //更新用户
                $info['uid'] = AC::HOST_UID;
                $userGroups     = $this->groupMembersModel->getUserGroupAllCache($info['uid']);
                $userGroupCache = $this->checkUserInitGroupsOrmUids($info['uid'], $userGroups);
                $gids = array();
                if ($userGroupCache['gids']) {
                    $gids =  $userGroupCache['gids'];
                }
                $info['status']    =    '1';
                $info['gtype']     =    '1';
                $this->groupMembersModel->setGroupMember($info);

                // 更新缓存
                $newGids = array_diff($gids, array($info['gid']));

                // 更新数据库
                $this->delMemberNum($info, $newGids);

                //设置完成更新用户圈子信息的缓存
                if(isset($userGroups['topGid']) && !empty($userGroups['topGid'])) {
                    $topGids = explode(',', $userGroups['topGid']);
                    $topGids = array_diff($topGids, array($info['gid']));
                    if(empty($topGids)){
                        $data = ['topGid' => ''];
                    }else{
                        $data = [
                            'topGid' => implode(',', $topGids)
                        ];
                    }
                    $this->diaryListCacheModel->addGroupUserCache($info['uid'], $data);
                }

		    	AC::$errorNo = 'GRC012';
	        	return FALSE;
			}
			$data = array();
			$data['group_info']					=	$this->groupData($result,$userGroupCache['gids']);
			$data['group_info']['topic_list']	=	$this->getTopicList(array('gid'=>$result['gid'],'start'=>0,'length'=>10));	
			return $data;
		}/*}}}*/
		#附件详情
		private function attachmentInfo($info)/*{{{*/
		{
			$result = $this->attachmentModel->getAttachmentInfo($info);
			return $result;
		}/*}}}*/
		#发现组
		public function findGroup($info)/*{{{*/
		{
			$result 		= 	$this->groupInfoModel->findGroup($info);
			$userGroups     = 	$this->groupMembersModel->getUserGroupAllCache(AC::HOST_UID);
			$userGroupCache =   $this->checkUserInitGroupsOrmUids(AC::HOST_UID, $userGroups);
			
			if($result)
			{
				$data = $group = array();
				foreach ($result as $value)
				{
					$groupInfo = $this->groupInfoModel->groupAddRedis($value['gid']);
					$group = $this->groupData($groupInfo,$userGroupCache['gids']);
					$group['new_topic'] = $this->getTopicList(array('gid'=>$value['gid'],'length'=>1,'new_topic'=>1,'no_display'=>1));
					$data['groups'][] = $group;
				}
				$data['counts'] = count($data['groups']);
				return $data;
			}
			return $result;
		}/*}}}*/
		
		// 搜索话题
		public function searchTopic($info){
		    // 字符判断
		    $info['key_word']       	 =	UK::getstr($info['key_word'], 100,'',1);
		    if (strlen($info['key_word']) < 1){
		        return (Object) array();
		    }
		    $list     = $this->groupInfoModel->getSearchTopicInfo($info);
		    if (empty($list)){
		        return (Object) array();
		    }
		    $result   = array();
		    foreach ( $list as $value ){
		        // 从缓存中获取话题
		        $topic      =   $this->topicModel->topicAddRedis($value);
		        if (empty($topic)){
		            continue;
		        }
		        // 从redis中查找圈子信息
		        $groupInfo  =   $this->groupInfoModel->groupAddRedis($topic['gid']);
		        if (empty($groupInfo)){
		            continue;
		        }
		        $topic['gname'] = $groupInfo['name'];
		        $topic['gAvatar'] = $groupInfo['avatar'];
		        $result['topics'][] 	= 	$this->topicData($topic,1);
		        	
		    }
		    $result['counts']    =    count($result['topics']);
		    return $result;
		}

		public function choiceGroup($info) {
		    $start  = isset($info['start']) ? intval($info['start']) : 0;
            $len    = isset($info['len']) ? intval($info['len']) : 5;

            $choiceGroup = $this->groupInfoModel->getChoiceGroup($start, $len);
            $result = [];
            if($choiceGroup) {
                foreach ($choiceGroup as $value) {
                    if (empty($value['id'])) continue;
                    $tmp = [];
                    $tmp['id'] = $value['id'];
                    $tmp['image'] = $value['image_url'];
                    $tmp['action'] = $value['action_url'];
                    $tmp['link'] = $value['link_url'];
                    $tmp['name'] = $value['name'];
                    $result[] = $tmp;
                }
            }
            //为空则取官方
            if(empty($result)) {
                $groupList = AC::$groupList;     //精选默认：新人报道／护肤美妆／爱晒美图／星座生肖／明星八卦
                $defaultImageList = AC::$defaultImageList;
                foreach ($groupList as $value){
                    if(empty($value)) continue;
                    $groupInfo = $this->groupInfoModel->groupAddRedis($value);
                    if(empty($groupInfo)) continue;
                    $groupInfo = $this->groupData($groupInfo, array());

                    $tmp = [];
                    $tmp['id']      = isset($groupInfo['id']) ? $groupInfo['id'] : $groupInfo['gid'];
                    $tmp['image']   = empty($defaultImageList[$value]) ? $groupInfo['cover'] : $defaultImageList[$value];
                    $tmp['action']  = isset($groupInfo['action']) ? $groupInfo['action'] : 'pinksns://group/info?gid=' . $groupInfo['gid'];
                    $tmp['link']    = isset($groupInfo['link']) ? $groupInfo['link'] : '';
                    $tmp['name']    = isset($groupInfo['name']) ? $groupInfo['name'] : '';
                    $result[] = $tmp;
                }
                return $result;
            }

		    return $result;
        }

        /**
         * 根据分类获取圈子列表
         * @param $info
         * @return array|bool|object
         */
        public function getGroupByCategory($info) {
		    $category = isset($info['category']) ? $info['category'] : 1;
            $start = isset($info['start']) ? $info['start'] : 0;
		    $length = isset($info['length']) ? $info['length'] : AC::GROUP_LIST_DISPLAY_LEN;
            // 分类1默认为官方圈子
            if($category == 1) {
                if($start > 0) return array();
                $groups = $this->groupInfoModel->getOfficialGroup();
            }else{
                $groups =   $this->groupInfoModel->getGroupListByCategory($category, $start, $length);
            }
            $groups =   $this->rebuildGroupData($groups);

            return $groups;
        }

        /**
         * 组装圈子信息
         * @param $groupList
         * @return array
         */
        private function rebuildGroupData ($groupList) {
		    if(empty($groupList)) return array();
		    $hostUid = AC::HOST_UID;
            $userGroups     = $this->groupMembersModel->getUserGroupAllCache($hostUid);
            $userGroupCache = $this->checkUserInitGroupsOrmUids($hostUid, $userGroups);

            $data = $group = array();
            foreach ($groupList as $value)
            {
                $pauseList = $this->diaryListCacheModel->getPauseGroupList();
                if(in_array($value, $pauseList)) {
                    continue;
                }
                $groupInfo  		= $this->groupInfoModel->groupAddRedis($value);
                if($groupInfo['category']  == 12){
                    continue;   //淘汰分类
                }
                $group			= $this->groupData($groupInfo, $userGroupCache['gids']);
                if(empty($group) || empty($group['gid'])){
                    continue;
                }
                $group['new_topic'] 	= array();
                $data['groups'][] 	= $group;
            }
            $data['counts'] = count($data['groups']);
            return $data;
        }

        /**
         * 获取所有分类
         * @return array|object
         */
        public function getAllGroupCategory() {
            $result =  $list =  array();
            $list   =  $this->groupInfoModel->getGroupCategories();

            if (empty($list)){
                return (Object) array();
            }
            foreach ($list as $val) {
                $tmp = [
                    'cid'            =>    '1',
                    'cname'          =>    '',
                    'introduction'   =>    '',
                    'icon_large'     =>    '',
                    'icon_small'     =>    '',
                ];
                $catInfo    =    $this->groupInfoModel->getGroupCategoryInfo($val['cid']);

                isset($catInfo['cid'])           &&    $tmp['cid']          =    strval($catInfo['cid']);
                isset($catInfo['name'])          &&    $tmp['cname']        =    strval($catInfo['name']);
                isset($catInfo['introduction'])  &&    $tmp['introduction'] =    strval($catInfo['introduction']);
                isset($catInfo['icon_large'])    &&    $tmp['icon_large']   =    strval($catInfo['icon_large']);
                isset($catInfo['icon_small'])    &&    $tmp['icon_small']   =    strval($catInfo['icon_small']);

                // 临时更改相关圈子的名称
                if($tmp['cid'] == 1) {
                    $tmp['cname'] = '官方';
                }
                if($tmp['cid'] == 11) {
                    $tmp['cname'] = '其他';
                }
                // 校园已转移到其他分类
                if($tmp['cid'] == 8) {
                    continue;
                }
                $start = 0;
                $length = 1;
                $groups =   $this->groupInfoModel->getGroupListByCategory($tmp['cid'],$start,$length);
                $groups =   $this->rebuildGroupData($groups);
                $tmp['cat_group_list'] = $groups;

                $result[] = $tmp;
            }
            return ['cats' => $result];
        }

        /**
         * 圈子置顶
         * @param $info
         * @return bool|mixed
         */
        public function stickGroup($info) {
            $uid = isset($info['uid']) ? $info['uid'] : 0;
            $gid = isset($info['gid']) ? $info['gid'] : 0;
            if($uid < 0 || $gid < 0) {
                AC::$errorNo = 'GRC020';        //uid和gid不能为空
                return false;
            }
            $groupInfo = $this->groupInfoModel->groupAddRedis($gid);
            if(empty($groupInfo)) {
                AC::$errorNo = 'GRC012';        //圈子不存在
                return false;
            }

            $userGroups     = $this->groupMembersModel->getUserGroupAllCache($uid);
            $userGroupCache = $this->checkUserInitGroupsOrmUids($uid, $userGroups);
            $gids = array();
            if ($userGroupCache['gids']) {
                $gids =  $userGroupCache['gids'];
            }
            if (!in_array($gid, $gids) && $groupInfo['uid'] != $uid ){
                AC::$errorNo    =   'GRC021';       //加入圈子后才可以置顶
                return FALSE;
            }
            $topGid = array();
            if(isset($userGroups['topGid']) && !empty($userGroups['topGid'])) {
                $topGid = explode(',', $userGroups['topGid']);
                if(in_array($gid, $topGid)) {
                    AC::$errorNo    =   'GRC022';       //不能重复置顶
                    return FALSE;
                }
            }
            array_unshift($topGid, $gid);
            $data = [
                'topGid' => implode(',', $topGid)
            ];
            $this->diaryListCacheModel->addGroupUserCache($uid, $data);
            return true;
        }

        /**
         * 取消圈子置顶
         * @param $info
         * @return bool|mixed
         */
        public function unStickGroup($info) {
            $uid = isset($info['uid']) ? $info['uid'] : 0;
            $gid = isset($info['gid']) ? $info['gid'] : 0;
            if($uid < 0 || $gid < 0) {
                AC::$errorNo = 'GRC020';        //uid和gid不能为空
                return false;
            }
            $groupInfo = $this->groupInfoModel->groupAddRedis($gid);
            if(empty($groupInfo)) {
                AC::$errorNo = 'GRC012';        //圈子不存在
                return false;
            }

            $userGroupInfo = $this->diaryListCacheModel->getUserGroupAllCache($uid);

            if(!isset($userGroupInfo['topGid']) || empty($userGroupInfo['topGid'])) {
                AC::$errorNo    =   'GRC023';       //圈子未置顶
                return FALSE;
            }
            $topGid = explode(',', $userGroupInfo['topGid']);
            if(!in_array($gid, $topGid)) {
                AC::$errorNo    =   'GRC023';       //圈子未置顶
                return FALSE;
            }
            unset($topGid[array_search($gid, $topGid)]);
            $data = [
                'topGid' => implode(',', $topGid)
            ];
            $this->diaryListCacheModel->addGroupUserCache($uid, $data);
            return true;
        }
		
		#所有组
		public function allGroup($info)/*{{{*/
		{
			$result = $this->groupInfoModel->allGroup($info);
			if (empty($result)) {
			    return (Object) array();
			}

			$userGroups     = $this->groupMembersModel->getUserGroupAllCache(AC::HOST_UID);
			$userGroupCache = $this->checkUserInitGroupsOrmUids(AC::HOST_UID, $userGroups);
			
			$data = $group = array();
			foreach ($result as $value)
			{
				$groupInfo  		= $this->groupInfoModel->groupAddRedis($value['gid']);
				$group			= $this->groupData($groupInfo, $userGroupCache['gids']);
				$group['new_topic'] 	= array();
				$data['groups'][] 	= $group;
			}
			$data['counts'] = count($data['groups']);
			return $data;
		}/*}}}*/
		
		/**
		 * 根据标签获取圈子列表
		 * @param unknown $info
		 * @return boolean|StdClass|number
		 */
		private function getGroupsByTag($info){
		    $uid = AC::HOST_UID;
		    $tag = UK::getstr($info['tag'], 100);
		    if (strlen($tag) < 1){
		        AC::$errorNo = 'GRC001';
		        return FALSE;
		    }
		    
		    // 获取tag_id
		    $tagInfo = Tags::getTagInfo($tag);
		    if (empty($tagInfo)){
		        return (Object) array();
		    }
		    $tag_id = $tagInfo['id'];
		    
		    // 获取圈子id列表
		    $groupIds = Tags::getGroupsByTag($tag_id);
		    if (empty($groupIds)){
		        return (Object) array();
		    }
		    
		    // 获取我加入的全部圈子
		    $userGroups     = $this->groupMembersModel->getUserGroupAllCache($uid);
		    $userGroupCache = $this->checkUserInitGroupsOrmUids($uid, $userGroups);
		    
		    $data = $group = array();
		    foreach ($groupIds as $value)
		    {
		        $groupInfo  		= $this->groupInfoModel->groupAddRedis($value);
		        $group			= $this->groupData($groupInfo, $userGroupCache['gids']);
		        $group['new_topic'] 	= array();
		        $data['groups'][] 	= $group;
		    }
		    $data['counts'] = count($data['groups']);
		    return $data;
		}
		
		/**
		 * 推荐粉粉圈
		 * @param unknown $info
		 * @return StdClass
		 */
		private function getRecommentGroups($info){
		    $uid    = AC::HOST_UID;
		    $result = array();

		    // 我加入的圈子
		    $userGroups     = $this->groupMembersModel->getUserGroupAllCache($uid);
		    $userGroupCache = $this->checkUserInitGroupsOrmUids($uid, $userGroups);
		    $myJoinedGroups = $userGroupCache['gids'];

            $start  = isset($info['start']) ? intval($info['start']) : 0;
            $len    = isset($info['len']) ? intval($info['len']) : 5;
            $len = $start + $len - 1;
            $groupList = $this->diaryListCacheModel->getRecommendGroup($start, $len);
		    
		    // 返回圈子列表
		    $tmp = array();
		    foreach ($groupList as $value){
		        $groupInfo  		= $this->groupInfoModel->groupAddRedis($value);
		        if (empty($groupInfo)){
		            continue;
		        }
		        
		        $group			    = $this->groupData($groupInfo, $myJoinedGroups);
		        $group['new_topic'] = array();
		        $tmp[] = $group;
		    }
		    
		    $result['groups']   = $tmp;
		    $result['counts']   = count($result['groups']);
		    return $result;
		}
		
		/**
		 * 添加附件1为图片2为语音
		 * @param unknown $info
		 * @return boolean
		 */
		private function addAttachment($info)/*{{{*/
		{
		    // 图片附件
		    if (is_array($info['attachment'])  &&  count($info['attachment']) > 0 ) {
		        $tmpInfo    =   array(
		                'tid'        =>  $info['tid'],
		                'uid'        =>  $info['author_uid'],
		                'pid'		 =>	 $info['commentId'],
		                'attachment' =>  $info['attachment'],
		                'type'       =>  1,
		        );
		    
		        $this->attachmentModel->addAttachment($tmpInfo);
		    }
		    // 语音附件
		    if (is_array($info['voice'])  &&  count($info['voice']) >   0)
		    {
		        $voiceInfo    =   array(
		                'tid'        =>  $info['tid'],
		                'uid'        =>  $info['author_uid'],
		                'pid'		 =>	 $info['commentId'],
		                'attachment' =>  $info['voice'],
		                'type'       =>  2,
		        );
		        $this->attachmentModel->addAttachment($voiceInfo);
		    }
			
			return TRUE;
		}/*}}}*/
		#修改附件
		private function editAttachment($info)/*{{{*/
		{
			$result = $this->attachmentModel->editAttachment($info);
			if (empty($result))
			{
				AC::$errorNo	=	'GRC007';
				return  FALSE;
			}
		
			return TRUE;
		}/*}}}*/
		#创建者可以做的
		private function createrCanDo($info)/*{{{*/
		{
			#获取小组创建人uid
			$groupInfo = $this->groupInfoModel->groupAddRedis($info['gid']);
			if ($groupInfo['uid'] != $info['uid'])
			{
				AC::$errorNo    =   'GRC008';
				return FALSE;
			}
			
			return TRUE;
		}/*}}}*/			

		#组人数-
		private function delMemberNum($info,$gids)/*{{{*/
		{
		    $result = $this->groupInfoModel->delMemberNum($info, 1);
		    // 缓存更新相应字段
		    $this->diaryListCacheModel->addGroupCount($info['gid'], 'member_num' , -1);
		    $data = array(
		    		'gids'	=>	implode(",", $gids),
		    		'gtime'	=>	AC::SERVER_TIME
		    );
		    $this->diaryListCacheModel->addGroupUserCache($info['uid'], $data);
		    return $result;
		}/*}}}*/
		#组人数+
		private function addMemberNum($info,$gids)/*{{{*/
		{
		    $result = $this->groupInfoModel->addMemberNum($info, 1);
		    // 缓存更新相应字段
		    $this->diaryListCacheModel->addGroupCount($info['gid'], 'member_num' , 1);
		    $data = array(
		    		'gids'	=>	implode(",", $gids),
		    		'gtime'	=>	AC::SERVER_TIME,
		            	'ftime' =>  AC::SERVER_TIME
		    );
		    $this->diaryListCacheModel->addGroupUserCache($info['uid'], $data);
		    return $result;
		}/*}}}*/
		#获取成员信息
		private function getUserInfo($uid)/*{{{*/
		{
			$info   =   $this->autoUidModel->getUserInfo($uid);
			if (empty($info)) {
			    return (Object) array();
			}
			$result =   array(
					'uid'       =>  $info['uid'],
					'avatar'	=> 	$info['avatar'],
					'nickname'  =>  $info['nickname'],
					'signature' =>  $info['signature']
			);
			return  $result;
		}/*}}}*/
		
		#话题区
		
		#删除话题
		public function removeTopic($info)/*{{{*/
		{
            if (empty($info['uid']) || empty($info['tid']) || empty($info['author_uid']) || empty($info['gid']))
            {
                AC::$errorNo    =   'GRC001';
                return  FALSE;
            }
            $groupInfo = $this->groupInfoModel->groupAddRedis($info['gid']);
            $uidList =  [];
            if(!empty($groupInfo['mUids'])) {
                $uidList = explode(',', $groupInfo['mUids']);
            }
            //非作者非管理员非队长不能删除
            if ($info['uid'] !=  $info['author_uid'] && $info['uid'] !=  $groupInfo['uid'] && !in_array($info['uid'], $uidList))
            {
                AC::$errorNo    =   'GRC008';
                return  FALSE;
            }

            // 先查询该话题详情
            $topicInfo = $this->topicModel->topicAddRedis($info);
            if (empty($topicInfo)){
                AC::$errorNo = 'GRC002';
                return FALSE;
            }

            $topic 	= $this->topicModel->removeTopic(array('tid'=>$info['tid']));
            $num 	= $this->groupInfoModel->delTopicNum($info, 1);
            // 删除缓存中的话题信息
            $this->diaryListCacheModel->delTopicInfo($info['tid']);
            if (intval($topicInfo['display']) > 0){
                // 更新圈子置顶话题的tid列表
                $groupInfo = $this->groupInfoModel->groupAddRedis($info['gid']);
                $tidsArr   = json_decode($groupInfo['top_tids'], true);
                if (in_array($info['tid'], $tidsArr)){
                    $tidsArr = array_diff($tidsArr, array($info['tid']));
                    $this->groupInfoModel->editGroup(array('gid' => $groupInfo['gid'], 'top_tids' => json_encode($tidsArr)));
                    $this->diaryListCacheModel->delGroupCache($groupInfo['gid']);
                }
            }
            if (empty($num))
            {
                AC::$errorNo = 'GRC007';
                return  FALSE;
            }
            AC::$userStatistics[$info['author_uid']]['topicTimes']  =   -1;

            // 查找相应日记
            $bodyId = $label = $secret = 0;
            $topicDiarys = $this->diaryListModel->getAllTopicDiarys($info['author_uid']);
            foreach ($topicDiarys as $val){
                $extras = json_decode($val['extras'], true);
                if (($extras['topic'][0]['url_type_id'] == $info['tid']) && $extras['topic'][0]['url_type'] == 'topic'){
                    $bodyId = $val['bodyId'];
                    $label  = $val['label'];
                    $secret = $val['secret'];
                    break;
                }
            }

            // 删除相应日记
            if ($bodyId){
                $diaryInfo = array('uid' => $info['author_uid'], 'bodyId' => $bodyId);
                $result = $this->diaryListModel->removeDiaryList($diaryInfo);
                $this->diaryBodyModel->removeDiaryBody($diaryInfo);
                $this->diaryAttachmentModel->removeDiaryAttachment($diaryInfo);
                $this->diaryListCacheModel->removeDiaryAll($bodyId, $info['author_uid'], $label);
                //$this->lbsModel->removeLbs($diaryInfo);
                if (AC::$errorNo){
                    AC::$errorNo = NULL;
                }
                if (!empty($secret)){
                    AC::$userStatistics[$diaryInfo['uid']]['secretDiaryTimes']  =   -1;
                }else{
                    AC::$userStatistics[$diaryInfo['uid']]['diaryTimes']        =   -1;
                }
            }
            //私信通知
            if($info['uid'] != $info['author_uid']) {
                $mUserInfo = $this->autoUidModel->getUserInfo($info['author_uid']);
                $messageModel = new MessageBoxModel();
                $param = array(
                    'uid' => '1',
                    'mUid' => $info['author_uid'],
                    'nickname' => '粉粉小秘书',
                    'mNickname' => $mUserInfo['nickname'],
                    'content' => '【圈子通知】你在' . $groupInfo['name'] . '中发布的内容被管理员删除，请发布合规的内容。',
                );
                $messageModel->sendAbilityMessage($param);
            }
            return  TRUE;
		}
		
		
		/**
		 * 话题详细
		 * @param unknown $info
		 * @return boolean
		 */
		public function getTopicInfo($info)/*{{{*/
		{
			if (empty($info['tid']))
			{
				AC::$errorNo = 'GRC001';
				return FALSE;
			}
			// 从缓存中获取话题
			$topic      =   $this->topicModel->topicAddRedis($info);
		    if (empty($topic) || $topic['status'] > 0){
		        AC::$errorNo = 'GRC002';
		        return FALSE;
		    }
			
		    // 被拉黑不能看列表
		    $access =   $this->checkAccessPremission($topic['uid']);
		    if (empty($access)) return  FALSE;
		    
		    // 从redis中查找圈子信息
		    $groupInfo  =   $this->groupInfoModel->groupAddRedis($topic['gid']);
		    if (empty($groupInfo)){
		        AC::$errorNo = 'GRC012';
		        return FALSE;
		    }
		    
			$topic['gname'] = $groupInfo['name'];
			$topic['gAvatar'] = $groupInfo['avatar'];
			$topic 	= 	$this->topicData($topic);
			$result['topic_info'] 	= 	$topic;
			
			// 话题投票
			$vote = $this->voteModel->getVoteInfo($topic['tid'], $topic['uid'], $topic['vote'], AC::HOST_UID);
			$result['topic_info']['vote'] =$vote; //返回投票信息

            $uidList =  [];
            if(!empty($groupInfo['mUids'])) {
                $uidList = explode(',', $groupInfo['mUids']);
            }
            $hostUid = AC::HOST_UID;
            if($groupInfo['uid'] == $hostUid || in_array($hostUid, $uidList)) {
                $result['topic_info']['is_manager'] = 1; //是否管理人员
            }else{
                $result['topic_info']['is_manager'] = 0; //是否管理人员
            }
			
			// 话题评论列表
			$data = array();
			$data['tid']    	= $topic['tid'];
			$data['author_uid'] = $topic['uid'];
			$data['start']  	= 0;
			$data['length'] 	= 10;
			$comment 			= $this->getTopicCommentList($data);
			$result['topic_info']['comment_list'] = $comment;
			// 查看数自增
			$this->topicModel->addViewNum($info);
			$this->diaryListCacheModel->addUserViewTopicInfo(AC::HOST_UID, $topic['tid']);
			return $result;
		}/*}}}*/

		#小组话题列表
		public function getTopicList($info)/*{{{*/
		{
		    if (empty($info['gid'])) {
		        AC::$errorNo = 'GRC001';
		        return FALSE;
		    }
		    // 圈子是否存在
		    $groupInfo  =   $this->groupInfoModel->groupAddRedis($info['gid']);
		    if (empty($groupInfo))
		    {
		    	AC::$errorNo = 'GRC012';
		    	return FALSE;
		    }
		    $result = $this->topicModel->getTopicList($info);
    		if (empty($result)) {
    			return (Object) array();
    		}
    		
    		$data = array();
    		// 组装话题列表信息,并将话题图片获取
    		foreach ($result as $value)
    		{
    			$res  = $this->topicModel->topicAddRedis($value);
    			$res['gname']		= $groupInfo['name'];
    			$res['gAvatar']		= $groupInfo['avatar'];
    			if (empty($res['gid'])) {
    			    continue;
    			}

    			$res['show_digest'] = $info['show_digest'];
    			$res['new_topic']   = $info['new_topic'];
    			$list = $this->topicData($res,1);
    			if(intval($info['show_digest']) < 1 || intval($info['new_topic']) < 1){
    				$list['time']	= intval($list['last_reply'])  > 0 ? strval($list['last_reply']) : '0';
    			}
    			$data['topics'][]       =   $list;
    		}
    		$data['counts'] = count($data['topics']);
    		return $data;
		}/*}}}*/
		
		#话题发布者才能删除、修改对应的
		private function checkTopicUser($info)/*{{{*/
		{
			$topicUser = $this->topicModel->getOneTopic($info);
			$result = array(
					'uid'	=>	$topicUser['uid']
			);
			
			return $result;
		}/*}}}*/
		
		#获取评论者uid
		private function getCommentUid($info)/*{{{*/
		{
			$topicInfo = $this->topicCommentsModel->getCommentUid($info);
			$result = array(
					'uid'	=>  $topicInfo['uid']
			);
				
			return $result;
		}

        /**
         * 获取话题的评论列表
         * @param $info
         * @return array|bool
         */
		public function getTopicCommentList($info)
		{
		    if (intval($info['tid']) < 1 || intval($info['author_uid']) < 1){
		        AC::$errorNo    =   'GRC001';
		        return  FALSE;
		    }
		    
		    // 被拉黑不能看列表
		    $access =   $this->checkAccessPremission($info['author_uid']);
		    if (empty($access)) return  FALSE;
		    
		    // 话题是否存在
		    $topic  =   $this->topicModel->topicAddRedis($info);
		    if (empty($topic)){
		        AC::$errorNo    =   'GRC002';
		        return  FALSE;
		    }
		    // 圈子是否存在
		    $groupInfo  =   $this->groupInfoModel->groupAddRedis($topic['gid']);
		    if (empty($groupInfo))
		    {
		    	AC::$errorNo = 'GRC012';
		    	return FALSE;
		    }
 
		    $start  =   0;
		    $length =   AC::COMMENT_LIST_DISPLAY_LEN;
		    isset($info['start'])   &&  $start  =   $info['start'];
		    isset($info['length'])  &&  $length =   $info['length'];
		    if ($start  <   0)  $start  =   0;
		    
		    // 楼层跳转
		    $total_rpnum = intval($topic['response_num']);
		    $position    = 0;
		    $check       = FALSE;
		    isset($info['position'])    &&    $position    =    intval($info['position']);
		    if($position > 0 && $position <= $total_rpnum ){
		        $check = TRUE;
		        $page  = ceil(($position + 1) / $length);
		        $start = intval(($page - 1) * $length);
		    }
		    // 只看楼主
		    if (isset($info['author']) && intval($info['author']) > 0)
		    {
		    	$result =   $this->topicCommentsModel->getLandlordCommentsList($info, $start, $length);
		    }
		    // 按帖子最新回复时间倒序
		    if (isset($info['new_comment']) && intval($info['new_comment']) > 0)
		    {
		        if ($check){
		            $page = floor((($total_rpnum + 1) - $position) / $length);
		            $start = intval($page * $length);
		        }
		        
		    	$result =   $this->topicCommentsModel->getLatestCommentsList($info, $start, $length);
		    	$tmp 	  		  = $info;
		    	$tmp['position']  = 1;
		    	$firstComment     = $this->topicCommentsModel->getCommentUid($tmp);
				$first = current($result);
				$tmp['position']  = $first['position']+1;
				$prev  = $this->topicCommentsModel->getCommentUid($tmp);
				if (empty($prev)){
		    		array_unshift($result,$firstComment);
				}
		    }
		    // 获取话题评论列表
		    if (empty($info['author']) && empty($info['new_comment']))
		    {
		    	$result =   $this->topicCommentsModel->getTopicCommentList($info, $start, $length);
		    }
		    if (empty($result)){
		    	return (Object) array();
		    }
		    
		    // 评论分页，查看数加1
		    if ($start > 0) {
		        $this->diaryListCacheModel->changeTopicCount($info['tid'], 'view_num', 1);
		    }
		    
    		$data = array();
    		foreach ($result as $value)
    		{
    		    if (intval($value['parentId']) > 0){
        		    $commInfo['tid']           =    $info['tid'];
        		    $commInfo['author_uid']    =    $info['author_uid'];
        		    $commInfo['position']      =    $value['parentId'];
        		    $comment = $this->topicCommentsModel->getCommentUid($commInfo);
        		    $value['extra']  =   UK::getstr($comment['content'], '100','',1);
        		    if ($comment['status'] > 0){
        		        $value['extra'] = "此内容已被管理员删除";
        		    }
    		    }
                if ($value['status'] != '0'){
                    continue;
                }
    			$data['comments'][] = $this->commentsData($value);
    		}
    		$data['counts']	=	count($data['comments']);
    		return $data;
		}

        /**
         * 获取楼中楼评论
         * @param $info
         * @return array|bool
         */
        public function getChildComments($info) {
            if (intval($info['tid']) < 1 || intval($info['author_uid']) < 1 || intval($info['position']) < 1){
                AC::$errorNo    =   'GRC001';
                return  FALSE;
            }
            $info['position'] = $info['position'] + 1;
            // 话题是否存在
            $topic  =   $this->topicModel->topicAddRedis($info);
            if (empty($topic)){
                AC::$errorNo    =   'GRC002';
                return  FALSE;
            }
            // 圈子是否存在
            $groupInfo  =   $this->groupInfoModel->groupAddRedis($topic['gid']);
            if (empty($groupInfo))
            {
                AC::$errorNo = 'GRC012';
                return FALSE;
            }

            // 4.获取子评论列表
            $childComment = new ChildCommentModel();
            $comments = $childComment->getCommentsList(AC::COMMENT_TYPE_GROUP,$info['tid'], $info['position'], $info['positionId']);

            $result = $this->loopDataOfChildComment($comments, $info['author_uid']);
            if(empty($result)) return (Object)array();
            $result = ['commentList' => $result, 'counts' => count($result)];
            return $result;
        }

		#我评论的话题列表
		public function getMyTopics($info)/*{{{*/
		{	
			if (empty($info['uid']))
			{
				AC::$errorNo = 'GRC001';
				return FALSE;
			}
			
			// 被拉黑不能看列表
			$access =   $this->checkAccessPremission($info['uid']);
			if (empty($access)) return  FALSE;
			
			$result =   $this->topicModel->getMyTopics($info);
			if (empty($result)) {
			    return (Object) array();
			}
			$data = array();
			foreach ($result as $val)
			{
				$val  		 =    $this->topicModel->topicAddRedis($val);
				$groupInfo       =    $this->groupInfoModel->groupAddRedis($val['gid']);
				$val['gname']    =    $groupInfo['name'];
				$val['gAvatar']    =    $groupInfo['avatar'];
				$val['pid']      =    '1';
				$data['topics'][]=$this->topicData($val,1);
			}
			$data['counts']	=	count($data['topics']);
			return $data;
		}/*}}}*/
		
		/**
		 * 删除评论
		 * 注:评论是以作者id进行分表
		 * 删除只是标记删除,将status更改为1
		 * @param unknown $info
		 * @return boolean
		 */
		public function removeTopicComment($info)/*{{{*/
		{
			if (empty($info['uid']) || empty($info['tid']) || empty($info['position']) || empty($info['author_uid']))
			{
				AC::$errorNo    =   'GRC001';
				return  FALSE;
			}
			$positionId = isset($info['positionId']) ? $info['positionId'] : 0;
			
			// 返回数据position减1，此处要加上还原
			$info['position'] = $info['position']+1;
			
			$comUid = $this->topicCommentsModel->getCommentUid($info);
            if($positionId > 0){
                $childCommentInfo = $this->childCommentModel->getCommentInfo(AC::COMMENT_TYPE_GROUP, $info['tid'], $positionId);
                if ($info['uid'] != $childCommentInfo['uid'] || empty($comUid)) {
                    AC::$errorNo = 'GRC008';
                    return FALSE;
                }
                //删除子评论
                $removeStatus = $this->childCommentModel->removeChildComment(AC::COMMENT_TYPE_GROUP, $info['tid'], $positionId);
                if(!$removeStatus){
                    return false;
                }
                //更新父评论的附加字段
                $childCommentList = $this->childCommentModel->getCommentsList(AC::COMMENT_TYPE_GROUP, $info['tid'], $info['position']);
                $this->updateParentCommentExtend($info['position'], $info['tid'], $info['author_uid'], $childCommentList);
                //删除楼中楼评论返回主楼信息
                $commentInfo = $this->topicCommentsModel->getCommentInfo($info['position'], $info['tid'], $info['author_uid']);
                $commentInfo = $this->commentsData($commentInfo);
                return $commentInfo;
            }else {
                //删除主评论验证是否存在且uid是否相同
                if ($info['uid'] != $comUid['uid'] || empty($comUid)) {
                    AC::$errorNo = 'GRC008';
                    return FALSE;
                }
                $result = $this->topicCommentsModel->removeTopicComment($info);
                return $result;
            }
		}/*}}}*/
		
		// 未发表的话题列表
		private function getUnpublishedTopics($info)/*{{{*/
		{
			$result = $this->topicModel->getUnpublishedTopics($info);
			$data = array();
			// 组装话题列表信息,并将话题图片获取
			foreach ($result as $value)
			{
				$res  = $this->topicModel->topicAddRedis($value);
				$groupInfo  	=   $this->groupInfoModel->groupAddRedis($value['gid']);
				$res['gname']   = 	$groupInfo['name'];
				$res['gAvatar']   = 	$groupInfo['avatar'];
				$list = $this->topicData($res,1);
				$data['topics'][]       =   $list;
			}
			$data['counts'] = count($data['topics']);
			return $data;
		}
		
		/**
		 * 获取分类列表
		 * @param unknown $info
		 * @return number
		 */
		public function getGroupCategories($info){
		    $uid    =   intval($info['uid']);
		    
		    $result =  $tmp  =  $list =  array();
		    $list   =  $this->groupInfoModel->getGroupCategories();
		    if (empty($list)){
		        return (Object) array();
		    }
		    
		    $allGroups      =   $this->allGroup(array('length' => 100));
		    foreach ($list as $val){
		        $catInfo    =    $this->groupInfoModel->getGroupCategoryInfo($val['cid']);
		        if (empty($catInfo)){
		            continue;
		        }
		        $tmp        =    $this->restructCategoryData($catInfo, $allGroups);
		        $result['cats'][] = $tmp;
		    }
		    $result['counts'] = count($result['cats']);
		    return $result;
		}
		
		/**
		 * 检验用户初始化关注圈子及管理员
		 * return array
		 */
		private function checkUserInitGroupsOrmUids($uid, $userGroupInfo){
		    $result = array();
		    
		    // 初始化关注圈子
		    if (empty($userGroupInfo['gtime'])) {
		        $result = $this->groupMembersModel->initUserGroups($uid, AC::$initGroupsStr);
		    }
		    
		    // 初始化关注管理员
		    if (empty($userGroupInfo['ftime'])) {
		        // 圈子gid字符串
		        $gidsStr = '';
		        if (empty($userGroupInfo['gtime'])) {
		            $gidsStr = AC::$initGroupsStr;
		        }else{
		            $gidsStr = $userGroupInfo['gids'];
		        }
		        
		        // 一键关注管理员
		        $this->meFollowMany($uid, $gidsStr);
		        
		        // 更新缓存或数据库相应字段
		        $this->groupMembersModel->setUserGroupCache($uid, $userGroupInfo['gids']);
		        $this->groupMembersModel->initUpdateGroupUserFtime($uid);
		    }

		    // 默认情况及缓存修改
		    if (!empty($userGroupInfo['gtime'])) {
		        $result['gids']  = array();
		        if ($userGroupInfo['gids']){
		            $result['gids']  = explode(',', $userGroupInfo['gids']);
		        }
		        $result['gtime'] = $userGroupInfo['gtime'];
		        $result['ftime'] = $userGroupInfo['ftime'];
		    }

		    return $result;
		}
		
		/**
		 * 获取推荐话题列表
		 * @param unknown $info
		 * @return boolean|number
		 */
		public function getRecommendTopics($info){
		    $uid = intval($info['uid']);
		    if ($uid < 1){
		        AC::$errorNo    =   'GRC001';
		        return  FALSE;
		    }
		    
		    $start  = 0;
		    $length = AC::RECOMMENT_TOPIC_LIST_LEN;
		    isset($info['start'])     &&    $start    =    intval($info['start']);
		    isset($info['length'])    &&    $length   =    intval($info['length']);
		    if ($start < 0 || $length < 0){
		        $start  = 0;
		        $length = AC::RECOMMENT_TOPIC_LIST_LEN;
		    }
		    
		    $topics = $this->topicModel->getRecommendTopicList($start, $length);
		    $data = $tmp = array();
		    foreach ($topics as $value)
	        {
	            $res  = $this->topicModel->topicAddRedis(array('tid' => $value['tid']));
	            if (empty($res) || empty($res['gid'])){
	                continue;
	            }
	            $groupInfo  =   $this->groupInfoModel->groupAddRedis($res['gid']);
	            if (empty($res)){
	                continue;
	            }
	            $res['gname']		= $groupInfo['name'];
	            $res['gAvatar']		= $groupInfo['avatar'];
	            $res['show_digest'] = $info['show_digest'];
	            $res['new_topic']   = $info['new_topic'];
	            $list               = $this->topicData($res,1);
	            $list['time']	    = strval($list['last_reply']);
	            $data['topics'][]   =   $list;
	        }
	        $data['counts'] = count($data['topics']);
	        $this->syncCountWeightTopic($data['topics']);
			AC::$errorNo = null;
	        return $data;
		}

		private function syncCountWeightTopic($list)
		{
			foreach ($list as $val)
			{
				$tmp = array(
					'type' => 'topic',
					'type_id' => $val['tid'],
					'type_data' => array(
						'views' => $val['view_num'] ? $val['view_num'] : 1,
						'zfs'  => 0
					)
				);

				RedisPool::addCountWeightJob('countWeight', UK::JsonFormat($tmp) );
			}
		}
		
		//=============================数据格式化=========================\
		// 小组返回数据结构化
		private function groupData($info, $user_gids)/*{{{*/
		{
            $hostUid = AC::HOST_UID;
			$is_follow				=	in_array($info['gid'], $user_gids) ? 1 : 0;
			if($is_follow == 0 && $hostUid == $info['uid']){
                $is_follow = 1;
            }

			//置顶
			$topGroup  = $this->diaryListCacheModel->getTopGroups($info['category']);
			$is_top_category = in_array($info['gid'], $topGroup);

			$userTop   = $this->groupInfoModel->getUserTopGroup($hostUid);
			$is_top_user     = in_array($info['gid'], $userTop);
			$top = 0;
			if($is_top_user)  $top +=  1;
			if($is_top_category) $top += 2;

			//是否被推荐
            $score = $this->diaryListCacheModel->getGroupScore($info['gid']);
            $is_recommend = 0;
            if($score) $is_recommend = 1;

            //是否被封禁
            $this->diaryListCacheModel->deletePauseGroup();
            $pause = $this->diaryListCacheModel->getPauseGroupTime($info['gid']);
            $is_pause = 0;
            if($pause) $is_pause = 1;

			// 分类信息
            $catInfo    =    $this->groupInfoModel->getGroupCategoryInfo($info['category']);
            if($info['category'] == 11) {
                $catInfo['name'] = '其他';
            }

			$data = array();
			$data['id']				=	strval($info['gid']);
			$data['gid']			=	strval($info['gid']);
			$data['uid']			=	strval($info['uid']);
			$data['name']			=	strval($info['name']);
			$data['category']		=	strval($info['category']);
			$data['categoryName']   =   strval($catInfo['name']);
			$data['introduction']	=	strval($info['introduction']);
			$data['cover']			=	strval($info['cover']);
			$data['topic_num']		=	strval($info['topic_num']);
			$data['member_num']		=	strval($info['member_num']);
			$data['status']			=	strval($info['status']);
			$data['time']			=	strval($info['time']);
			$data['is_followed']	=	strval($is_follow);
			$data['new_topic_num']  =	strval($info['today_nums']);
			$data['gtype']  		=	strval($info['gtype']);
			$user   		        =	$this->autoUidModel->getUserInfo($info['uid']);
			$data['mUids']          =   empty($info['mUids'])  ? array() : explode(',',$info['mUids']);
			$data['display']        =   $top;
            $data['avatar']         =   isset($info['avatar']) ? strval($info['avatar']) : '';
            $data['manage_level']   =   0;
            $data['is_recommend']   =   $is_recommend;
            $data['is_pause']       =   $is_pause;
            $data['bannerInfo']     =   (object)array();
            if(!empty($info['extras'])) {
                $extraInfo = UK::parseData($info['extras']);
                if(empty($data['avatar'])) {
                    $data['avatar'] = isset($extraInfo['avatar']) ? $extraInfo['avatar'] : '';
                }
                $data['bannerInfo'] = isset($extraInfo['bannerInfo']) ? $extraInfo['bannerInfo'] : (object)array();
            }
            // cover 作为封面，当avatar没有值的时候用cover
            if(empty($data['avatar'])) {
                $data['avatar'] = strval($info['cover']);
            }
            // 旧版本限制圈子简介字数10个字
            $check = UK::checkVersion('5.71', '5.7.1');
            if($check){
                $te = '';
                if(strlen($data['introduction']) > 45) $te = '...';
                $data['introduction'] = UK::getstr($data['introduction'], 25, $te,1);
                $data['cover'] = $data['avatar'];
            }

            // 用户在圈子中的身份
            $hostUid == $data['uid'] && $data['manage_level'] = 1;   //创建人
            if(in_array($hostUid, $data['mUids']) && $data['manage_level'] == 0){
                $data['manage_level'] = 2;                              //管理员
            }
            $data['user']           =	$this->autoUidModel->checkIsMe($user);

			return $data;
		}
	
	    // 话题数据格式
	    public function topicData($info,$check = 0)/*{{{*/
	    {
            $group    		=  $this->groupInfoModel->groupAddRedis($info['gid']);
	    	$data = array();
	    	$data['id']			    = UK::intDeal($info['id']);
	    	$data['tid']			= UK::intDeal($info['tid']);
	    	$data['uid']			= UK::intDeal($info['uid']);
	    	$data['gid']			= UK::intDeal($info['gid']);
	    	$data['gname']			= !empty($group['name']) ? strval($group['name']) : '';
	    	$data['gAvatar']        = !empty($group['avatar']) ? strval($group['avatar']) : strval($group['cover']);
	    	$data['title']			= !empty($info['title']) ? strval($info['title']) : '';
	    	$data['content']		= !empty($info['abbreviation']) ? strval($info['abbreviation']) : '';
	    	$data['category']		= UK::intDeal($info['category']);
	    	$data['highlight']		= UK::intDeal($info['highlight']);
	    	$data['fav_num']		= UK::intDeal($info['favtimes']);
	    	$data['share_num']		= UK::intDeal($info['sharetimes']);
	    	$data['res_num']		= UK::intDeal($info['response_num']);
	    	$data['view_num']		= UK::intDeal($info['view_num'] + $info['response_num']);
	    	$data['recom_num']		= intval($info['recom_num'])  > 0 ? strval($info['recom_num']) : '0';
	    	$data['like_num']       = UK::intDeal($info['like_num']);
	    	$data['is_today']		= UK::isToday($info['time']) ? "1" : "0";
	    	$data['display']		= UK::intDeal($info['display']);
	    	$data['vote']		    	= UK::intDeal($info['vote']);//返回话题是否有投票
	    	$data['digest']			= UK::intDeal($info['digest']);
	    	$data['time']			= UK::intDeal($info['time']);
	    	$data['status']			= UK::intDeal($info['status']);
	    	$data['last_reply']		= UK::intDeal($info['last_reply']);
	    	$data['last_uid']		= UK::intDeal($info['last_reply_uid']);
	    	$data['last_user']		= !empty($info['last_reply_username']) ? strval($info['last_reply_username']) : '';
	    	$favor                  = 0;
	    	if (intval($check) < 1){
	    	    $favor				= $this->topicModel->getFavoriteTopicInfo(array('uid'=>AC::HOST_UID,'tid'=>$data['tid']));
	    	    if (empty($favor) || $favor['status'] == 1){
	    	        $favor = array();
	    	    }
	    	}
	    	$data['is_favor'] 		= !empty($favor)  ? '1' : '0';
	    	$data['recommend']       = UK::intDeal($info['recommend']);
	    	$data['attachments']    	= array();
	    	$data['voiceList']      	= array();
	    	// 判断传入的参数是否拥有缓存
	    	if (!empty($info['attachments']) || !empty($info['voiceList'])){
	    	    $data['attachments']    	=    $info['attachments'];
	    	    $data['voiceList']      	=    $info['voiceList'];
	    	}
	    	// 判断老版本
	    	$data['content'] = UK::tipsUpgrade($info['voiceList'], $data['content'], 'voice');
	    	$user			        = $this->autoUidModel->getUserInfo($info['uid']);
	    	$data['user']           	= $this->autoUidModel->checkIsMe($user);
	    	// 获取备注名
	    	$data['user']['nickname']     	= $this->autoUidModel->getRemarkName($data['user']);
	    	return $data;
	    }
	    
	    // 话题评论列表返回数据
	    private function commentsData($info)/*{{{*/
	    {
	    	$data = array();
		$data['id']			= strval($info['position']);
	    	$data['tid']			= strval($info['tid']);
	    	$data['uid']			= strval($info['uid']);
	    	$data['nickname']		= $info['nickname'];
	    	$data['author_uid']		= strval($info['author_uid']);
	    	$data['author_name']		= $info['author_name'];
	    	$data['gid']		    	= intval($info['gid']) > 0     ?  strval($info['gid']) : '0';
	    	$data['rUid']		    	= intval($info['rUid']) > 0     ?  strval($info['rUid']) : '0';
	    	$data['rNickname']		= empty($info['rNickname'])     ?  '' : strval($info['rNickname']);
	    	$data['parentId']		= intval($info['parentId']-1) > 0 ?  strval($info['parentId']-1) : '0';
	    	$data['position']		= strval($info['position']-1);
	    	$data['content']		= strval($info['content']);
	    	$data['status']		     = strval($info['status']);
	    	$data['extra'] = '';
	    	if (!empty($info['extra'])){
	    	    $data['extra'] = strval(Emotion::emotionToCharacter($info['extra']));
	    	}
	    	// 判断评论是否被删除
	    	if ($info['status'] != '0'){
	    	    $data['content']    =    '此内容已被管理员删除';
	    	}

	    	if ($this->diaryListCacheModel->isUidRemoving($info['uid'])){
	    	    $data['content']    =    '此内容已被屏蔽';
	    	}
	    	$data['time']			= strval($info['time']);
	    	$data['attachments']    = array();
	    	$data['voiceList']    	= array();
	    	if ((intval($info['attachment']) > 0 || intval($info['voice']) > 0) && $info['status'] == 0){
		    $tmp['pid']    	= $info['position'];
	    	    $tmp['uid']    	= $info['author_uid'];
	    	    $tmp['tid']    	= $info['tid'];
	    	    $attachment    	= $this->attachmentModel->getAttachmentInfo($tmp);
	    	    // 添加语音附件
	    	    $data['attachments'] =    $attachment['attachmentList'];
	    	    $data['voiceList']   =    $attachment['voiceList'];
	    	}
	    	$data['content'] = UK::tipsUpgrade($info['voiceList'], $data['content'], 'voice');
	    	
            // 表情对应的列表
            $data['imageList'] = array();
            $emotion_ids_mebuy = array();
            $data['childComments'] = (object)array();
            if (isset($info['extend']) && !empty($info['extend'])){
                $extend_arr     = json_decode($info['extend'], TRUE);
                $emotion_ids_mebuy = $extend_arr['shop_ids_mebuy'];
                $data['childComments'] = $this->childCommentModel->getCommentOfComment($info['extend'], 1);
            }

            if (empty($emotion_ids_mebuy) && $info['time'] < Emotion::$filter_emotion_update_time){
                $emotion_ids_mebuy = Emotion::$default_emotion_ids;
            }
            
            $data['imageList'] = Emotion::emotionToImgList($data['content'], $emotion_ids_mebuy);
            $data['content']   = Emotion::emotionToMark($data['content'], $emotion_ids_mebuy);
            $data['content'] = UK::removeBadLanguage($data['content']);
	    	
	    	$data['url_struct']     =   array();
	    	$user			=   $this->autoUidModel->getUserInfo($info['uid']);
	    	$data['user']           =   $this->autoUidModel->checkIsMe($user);
            
	    	// 获取备注名
	    	$user_author			=    $this->autoUidModel->getUserInfo($data['author_uid']);
	    	$data['author_name']    =    $this->autoUidModel->getRemarkName(array('uid'=>$data['author_uid'],'nickname'=>$user_author['nickname']));
	    	$data['nickname']       =    $this->autoUidModel->getRemarkName(array('uid'=>$data['uid'],'nickname'=>$data['user']['nickname']));
	    	$data['user']['nickname']    =  $data['nickname'];
	    	if (!empty($data['rUid']) && !empty($data['rNickname'])){
	    	    $user_reply			    =    $this->autoUidModel->getUserInfo($data['rUid']);
	    	    $rtmp['uid']            =    $data['rUid'];
	    	    $rtmp['nickname']       =    $user_reply['nickname'];
	    	    $data['rNickname']      =    $this->autoUidModel->getRemarkName($rtmp);
	    	}
	    	$data['is_favor'] 		= '0';
	    	// 是否当前用户收藏
	    	if ($data['position'] > 0) {
	    	    $favor = $this->topicModel->getFavoriteTopicInfo(array('uid'=>AC::HOST_UID,'tid'=>$data['tid'],'position'=>$info['position']));
	    	    if (!empty($favor) && $favor['status'] == 0) {
	    	        // status 0 收藏 1 取消
	    	        $data['is_favor'] = '1';
	    	    }
	    	}
	    	$data['favorites'] 		= strval($info['favorites']);
	    	
	    	// 活动跳转数据组装
	    	if($info['position'] == 1 && !empty($info['url_struct'])){
	    	    $data_url_struct = array(
	    	            'url_title'    =>    '',
	    	            'url_content'  =>    '',
	    	            'url_image'    =>    '',
	    	            'url_action'   =>    '',
	    	            'url_extend'   =>    array()
	    	    );
	    	
	    	    $url_struct = json_decode($info['url_struct'], true);
	    	    isset($url_struct['url_title'])      &&    $data_url_struct['url_title']      =    strval($url_struct['url_title']);
	    	    isset($url_struct['url_content'])    &&    $data_url_struct['url_content']    =    strval($url_struct['url_content']);
	    	    isset($url_struct['url_image'])      &&    $data_url_struct['url_image']      =    strval($url_struct['url_image']);
	    	    isset($url_struct['url_action'])     &&    $data_url_struct['url_action']     =    strval($url_struct['url_action']);
	    	    isset($url_struct['url_extend'])     &&    $data_url_struct['url_extend']     =    $url_struct['url_extend'];
	    	    $data['url_struct'][] = $data_url_struct;
	    	}
	    	
	    	return $data;
	    }

	    // 评论我的数据结构
	    private function commentMeListData($info){
	    	$data      =    array();
	    	$data['id']			= strval($info['id']);
	    	$data['tid']			= strval($info['tid']);
	    	$data['uid']			= strval($info['uid']);
	    	$userInfo 			= $this->autoUidModel->getUserInfo($data['uid']);
	    	$data['nickname']		= $userInfo['nickname'];
	    	$data['eUid']			= strval($info['eUid']);
	    	$data['eNickname']		= strval($info['eNickname']);
	    	$data['author_uid']		= strval($info['authorUid']);
	    	$data['author_name']		= strval($info['authorNickname']);
	    	$data['parentId']		= strval($info['parentId']);
	    	$data['type']			= strval($info['type']);
	    	$data['content']		= $info['content'];
	    	$data['time']			= strval($info['time']);
	    	// 从扩展字段中获取楼层以及圈子名字
	    	$extra    =    json_decode($info['extra_context'],true);
	    	$data['position']       = ($extra['position'] -1) < 0 ? 1 : $extra['position'] -1;
	    	$data['gname']          = $extra['gname'];
	    	$data['gid']            = empty($extra['gid']) ? '0' : strval($extra['gid']);
	    	$data['extra']          = $extra['extra'];
	    	$data['extra_uid']      = isset($extra['extra_uid']) ? $extra['extra_uid'] : '';
	    	$data['extra_nickname'] = isset($extra['extra_nickname']) ? $extra['extra_nickname'] : '';
            $data['positionId']		= isset($extra['positionId']) ? strval($extra['positionId']) : '0';
	    	$data['attachments']    = array();
	    	$data['voiceList']      = array();
	    	if (!empty($info['attachments']) || !empty($info['voiceList'])){
	    	    $data['attachments'] =    $info['attachments'];
	    	    $data['voiceList']   =    $info['voiceList'];
	    	}
	    	$data['content'] = UK::tipsUpgrade($info['voiceList'], $data['content'], 'voice');
	    	$user			        = $this->autoUidModel->getUserInfo($data['eUid']);
	    	$data['user']           = $this->autoUidModel->checkIsMe($user);
	        
	    	// 获取备注名
	    	$data['user']['nickname']  =    $this->autoUidModel->getRemarkName($data['user']);

            //过滤敏感词汇
            $data['content']		= UK::removeBadLanguage($data['content']);
            $data['extra']          = UK::removeBadLanguage($data['extra']);

            //验证存在

            $comment = $this->topicCommentsModel->getCommentInfo($data['position'] + 1, $info['tid'], $info['authorUid']);
            if ($comment['status'] > 0 || $info['status'] > 0){
                $data['content'] = "该回应已被删除";
            }
            if($data['parentId'] == 0){
                $data['extra_uid']      = '';
                $data['extra_nickname'] = '';
            }
            if($data['extra_uid'] && $data['extra_nickname'] == ''){
                $extra_user = $this->autoUidModel->getUserInfo($data['extra_uid']);
                if(empty($extra_user)){
                    AC::$errorNo = '';
                    $data['extra_uid'] = '';
                }else{
                    $data['extra_nickname'] = $this->autoUidModel->getRemarkName($extra_user);
                }
            }

            // 话题信息
            $topic      =   $this->topicModel->topicAddRedis($info);
            if ($topic){
                // 从redis中查找圈子信息
                $groupInfo  =   $this->groupInfoModel->groupAddRedis($topic['gid']);
                if($groupInfo){
                    $topic['gname'] = $groupInfo['name'];
                    $topic['gAvatar'] = $groupInfo['avatar'];
                    $topic 	= 	$this->topicData($topic);
                    $data['topic_info'] 	= 	$topic;
                }
            }else{
                $data['topic_info'] = (object)array();
            }
            if(AC::$errorNo) AC::$errorNo = '';

	    	return $data;
	    }
		// 附件列表
	    private function commentAttachment($info) {
	        $data    =    array();
	        foreach ($info['attachment']   as  $var)
	        {
	            $tmp['tid']            =   $info['tid'];
	            $tmp['uid']            =   $info['uid'];
	            $tmp['attachmentType'] =   $var['type'];
	            $tmp['attachmentPath'] =   $var['path'];
	            isset($var['info']) && $tmp['info'] = $var['info'];
	            $data[]    =    $tmp;
	        }
	        return $data;
	    }
	    // 构建收藏返回数据
	    private function rebuildFavoriteTopicData($info){
	        if (empty($info)){
	            return (Object) array();
	        }
	        $data    =    array();
	        $data['id']             =    strval($info['id']);
	        $data['uid']            =    intval($info['uid']) < 1 ? '0' : strval($info['uid']);
	        $data['tid']            =    intval($info['topic_id']) < 1 ? '0' : strval($info['topic_id']);
	        $data['favorite_uid']   =    intval($info['favorite_uid']) < 1 ? '0' : strval($info['favorite_uid']);
	        $data['favorite_name']  =    empty($info['favorite_name'])  ? '' : $info['favorite_name'];
	        $data['title']          =    empty($info['title']) ? '' : $info['title'];
	        $data['status']         =    strval($info['status']);
	        $data['time']           =    intval($info['time']) < 1 ? '0' : strval($info['time']);
	        $topicInfo              =    $this->topicModel->topicAddRedis($data);
	        if (empty($topicInfo)){
	            $topicInfo    =    (Object) array();
	        }
	        $data['topic_info']     =    $topicInfo;
	        $data['user']           =    AC::$hostUserBaseInfo;
	        // 获取备注名
	        $tmp['uid']             =    $data['uid'];
	        $tmp['nickname']        =    $data['favorite_name'];
	        $data['favorite_name']  =    $this->autoUidModel->getRemarkName($tmp);
	        
	        return $data;
	    }
	    
	    /**
	     * 圈子分类数据结构
	     * @param unknown $param
	     * @return unknown
	     */
	    private function restructCategoryData($param, $allGroups){
	        $data = array(
	                'cid'            =>    '1',
	                'cname'          =>    '',
	                'introduction'   =>    '',
	                'icon_large'     =>    '',
	                'icon_small'     =>    '',
	                'cat_group_list'       =>    array()
	        );
	        
	        isset($param['cid'])           &&    $data['cid']          =    strval($param['cid']);
	        isset($param['name'])          &&    $data['cname']        =    strval($param['name']);
	        isset($param['introduction'])  &&    $data['introduction'] =    strval($param['introduction']);
	        isset($param['icon_large'])    &&    $data['icon_large']   =    strval($param['icon_large']);
	        isset($param['icon_small'])    &&    $data['icon_small']   =    strval($param['icon_small']);

            $check = UK::checkVersion('5.71', '5.7.1');
	        if($check){
	            if($data['cid'] == 1) $data['cname'] = '新人';
            }

	        $tmp = array();
	        foreach ($allGroups['groups'] as $value){
	            //屏蔽其他圈子
	            if($value['gid'] > 50) {
	                continue;
                }
	            if($value['category'] == $data['cid']){
	                $tmp[] = $value;
	            }
	            continue;
	        }
	        $data['cat_group_list']['groups'] = $tmp;
	        $data['cat_group_list']['counts'] = count($tmp);
	        
	        return $data;
	    }

	    // 置顶后将信息更新至redis
	    private function topicStick($info, $topic){
	        $topicInfo   =    $this->topicModel->topicAddRedis($info);
	        if (!empty($topicInfo)){
	            $this->diaryListCacheModel->addTopicCache($info['tid'], $topic);
	        }
	    }
	    
	    // 增加话题时,圈子话题数自增,以及将话题加入缓存
	    private function groupTopicNum($info){
	        $this->diaryListCacheModel->addGroupCount($info['gid'], 'topic_num', '1');
	    }
	    
	    // 话题成员数,最后回复时间更新到redis中
	    private function topicChangeNum($info){
	        // redis计数更新时先查找一次是否存在
	        $topicInfo = $this->topicModel->topicAddRedis($info);
	        if (!empty($topicInfo)){
	            $this->diaryListCacheModel->changeTopicCount($info['tid'], 'response_num', 1);
	            $data['last_reply']          =   AC::SERVER_TIME;
	            $data['last_reply_uid']      =   $info['uid'];
	            $data['last_reply_username'] =   $info['nickname'];
	            $this->diaryListCacheModel->addTopicCache($info['tid'], $data);
	        }
	        // 加入数据库
	        $this->topicModel->addResponseNum($info);
	        $this->topicModel->setTopicLastTime($info);
	    }

	    //话题最后回复时间更新到redis中
        private function topicChangeLastTime($info){
            // redis计数更新时先查找一次是否存在
            $topicInfo = $this->topicModel->topicAddRedis($info);
            if (!empty($topicInfo)){
                $data['last_reply']          =   AC::SERVER_TIME;
                $data['last_reply_uid']      =   $info['uid'];
                $data['last_reply_username'] =   $info['nickname'];
                $this->diaryListCacheModel->addTopicCache($info['tid'], $data);
            }
            // 加入数据库
            $this->topicModel->setTopicLastTime($info);
        }
	 
	    // 更新今日话题数
	    private function addTodayGroupTopicNum($gid, $day){
	    	$isToday = UK::isToday($day);
	    	if(!$isToday){
	            //更新时间
	            $tmp = array('today' => AC::SERVER_TIME, 'today_nums' => 0);
	            $this->diaryListCacheModel->setGroupNodbCache($gid, $tmp);
	    	}
	    	$this->diaryListCacheModel->groupTodayNumIncrete($gid, "today_nums", 1);
	    }
	    
	    /**
	     * 关注某个用户
	     * @param unknown $uid
	     * @param unknown $fUid
	     * @return boolean|unknown
	    */
	    private function meFollow($uid, $fUid, $gmClose = FALSE){
	        if ($uid == $fUid){
	            return FALSE;
	        }
	        
	        $userBaseInfo       =   $this->autoUidModel->getUserInfo($uid);
	        if (!isset($userBaseInfo['nickname'])){
	            return  FALSE;
	        }
	         
	        $fUidBaseInfo       =   $this->autoUidModel->getUserInfo($fUid);
	        if (!isset($fUidBaseInfo['nickname'])){
	            return  FALSE;
	        }
	        
	        $nickname     =   $userBaseInfo['nickname'];
	        $fNickname    =   $fUidBaseInfo['nickname'];
	        
	        $result =   $this->followModel->meFollow(array('uid' => $uid, 'fUid' => $fUid));
	        if (AC::$errorNo){
	            AC::$errorNo = null;
	            return FALSE;
	        }
	        if ($result){
	            #redis增加好友列表 并重新获取用户关注列表
	            $this->diaryListCacheModel->addFriends($uid, $fUid);
	            $this->diaryListCacheModel->addFans($fUid, $uid);
	            if (!$gmClose){
	                RedisPool::addGearmanJob("timeline", array("uid"=>$uid), $uid);
	            }
	            
	            #  feed & statistics
	            AC::$userStatistics[$uid]['meFollowTimes']    =   1;
	            AC::$userStatistics[$fUid]['followMeTimes']   =   1;
	            // 关于我的轮询计数
	            AC::$userStatistics[$fUid]['newLikeMeTimes']  =   1;
	        }
	        return $result;
	    }
	    
	    /**
	     * 取消关注某个用户
	     * @param unknown $uid
	     * @param unknown $fUid
	     * @return boolean
	    */
	    public function removeFollow($uid, $fUid){
	        if ($uid == $fUid){
	            return FALSE;
	        }
            
	        $result =   $this->followModel->removeFollow(array('uid' => $uid, 'fUid' => $fUid));
	        if (AC::$errorNo){
	            AC::$errorNo = null;
	            return;
	        }
	        if ($result){
	            $this->diaryListCacheModel->delFriends($uid, $fUid);
	             
	            AC::$userStatistics[$uid]['meFollowTimes']    =   -1;
	            AC::$userStatistics[$fUid]['followMeTimes']   =   -1;
	        }
	        RedisPool::addGearmanJob("timeline", array("uid"=>$uid), $uid);
	        return  $result;
	    }
	    
    	public function meFollowMany($uid, $initGroupsStr){
    	    $initGroups = $fUidList = array();
    	    if (empty($initGroupsStr)) {
    	        return TRUE;
    	    }
    	    $initGroups = explode(',', $initGroupsStr);
    	    foreach ($initGroups as $value){
    	        $group = $this->groupInfoModel->groupAddRedis($value);
    	        if ($group['mUid'] > 0){
    	            $fUidList[] = $group['mUid'];
    	        }
    	    }
    	    if (empty($fUidList)){
    	        return TRUE;
    	    }
            $meFollowList    =    $this->diaryListCacheModel->getFriendsList($uid);
            $uids            =    array_diff($fUidList, $meFollowList);
            if (empty($fUidList) || empty($uids)){
                return FALSE;
            }
    
            $num = 0;
            foreach ($uids as $fUid){
                $gmClose = TRUE;
                $follow_result = $this->meFollow($uid, intval($fUid), $gmClose);
                if ($follow_result){
                    $num++;
                }
            }
            AC::$userStatistics[$uid]['meFollowTimes']    =   $num;
            RedisPool::addGearmanJob("timeline", array("uid"=>$uid), $uid);
            return TRUE;
        }
        
        
        
        
        
        //============================================ new ================================================

        /**
         * 话题评论
         * @param unknown $info
         * @return boolean|StdClass|multitype:number Ambigous <multitype:, multitype:Ambigous >
         */
        public function getTopicComments ($info) {
            $tid        = intval($info['tid']);
            $author_uid = intval($info['author_uid']);
            $show_author= intval($info['author']);
            $show_new   = intval($info['new_comment']);
            $position   = intval($info['position']);
            $host_uid   = AC::HOST_UID;
            
            // 参数判断
            if (empty($tid) || empty($author_uid)){
                AC::$errorNo    =   'GRC001';
                return  FALSE;
            }
            
            // 被拉黑不能看列表
            $access =   $this->checkAccessPremission($author_uid);
            if (empty($access)) return  FALSE;
            
            // 话题详情
            $topic  =   $this->topicModel->getTopicDetail($tid);
            if (empty($topic)) {
                AC::$errorNo    =   'GRC002';
                return  FALSE;
            }
            
            // 圈子详情
            $groupInfo  =   $this->groupInfoModel->groupAddRedis($topic['gid']);
            if (empty($groupInfo)) {
                AC::$errorNo = 'GRC012';
                return FALSE;
            }
            
            // 分页
            list($id, $start, $length) = UK::assemblePageData($info);
            
            // 话题列表
            $list = $this->getTopicCommentListByDiffModel($show_author, $show_new, $tid, $author_uid, $id, $position, $start, $length, $topic);
            if (empty($list)){
                return (Object) array();
            }
            
            // 组装返回数据
            $comments = $this->getComments($list, $host_uid);
            $result = array(
                'comments'  =>  $comments,
                'counts'    =>  count($comments)
            );
            
            return $result;
        }
        
        /**
         * 根据不同模式返回话题列表
         * @param unknown $show_author
         * @param unknown $show_new
         * @param unknown $tid
         * @param unknown $author_uid
         * @param unknown $id
         * @param unknown $position
         * @param unknown $start
         * @param unknown $length
         * @param unknown $topic
         * @return Ambigous <multitype:, boolean, Ambigous>
         */
        private function getTopicCommentListByDiffModel ($show_author, $show_new, $tid, $author_uid, $id, $position, $start, $length, $topic) {
            $list = array();
            // 楼层跳转
            list($start, $check) = $this->getFloorStart($position, $start, $length, $topic['response_num']);
            
            if ($show_author) {
                $list =   $this->topicCommentsModel->getAuthorComments($tid, $author_uid, $id, $start, $length);
            }elseif($show_new) {
                // 最新话题
                if ($check){
                    list($start, $check) = $this->getFloorStart($position, $start, $length, $topic['response_num']);
                }
            
                $firstComment = array();
                $list =   $this->topicCommentsModel->getNewComments($tid, $author_uid, $id, $start, $length);
                if ($list && empty($id)) {
                    $firstComment     = $this->topicCommentsModel->getCommentInfo(1, $tid, $author_uid);
                    array_unshift($list, $firstComment);
                }
            }else{
                // 默认评论列表
                $list = $this->topicCommentsModel->getTopicComments($tid, $author_uid, $id, $start, $length);
            }
            
            return $list;
        }
        
        /**
         * 楼层相关参数
         * @param unknown $position
         * @param unknown $start
         * @param unknown $length
         * @param unknown $total
         * @return multitype:boolean number
         */
        private function getFloorStart ($position, $start, $length, $total) {
            $check = FALSE;
            if($position > 0 && $position <= $total ){
                $check = TRUE;
                $start = intval((ceil(($position + 1) / $length) - 1) * $length);
            }
            
            if ($check){
                $start = intval(floor((($total + 1) - $position) / $length) * $length);
            }
            
            return array($start, $check);
        }
        
        /**
         * 获取话题列表
         * @param unknown $info
         * @return boolean|StdClass|unknown
         */
        public function getTopicLists ($info) {
            $gid    = intval($info['gid']);
            $digest = intval($info['show_digest']);
            $new    = intval($info['new_topic']);
            $host_uid = AC::HOST_UID;
            
            // 参数判断
            if ($gid) {
                AC::$errorNo = 'GRC001';
                return FALSE;
            }
            
            // 圈子是否存在
            $groupInfo  =   $this->groupInfoModel->groupAddRedis($gid);
            if (empty($groupInfo)){
                AC::$errorNo = 'GRC012';
                return FALSE;
            }
            
            // 分页
            list($id, $start, $length) = UK::assemblePageData($info);
            
            // 话题列表
            $list = $this->topicModel->getTopicLists($gid, $digest, $new, $start, $length);
            if (empty($list)) {
                return (Object) array();
            }
            
            // 处理数据
            $topics = $this->getTopics($list, $host_uid, $groupInfo, $digest, $new);
            $result = array(
                'topics'    =>  $topics,
                'counts'    =>  count($topics)
            );
            
            return $result;
        }
        
        /**
         * 话题详情
         * @param unknown $tid
         * @return boolean|Ambigous <boolean, StdClass, multitype:number >
         */
        public function getTopicDetail ($info) {
            $tid = intval($info['tid']);
            $host_uid = AC::HOST_UID;
            
            // 参数判断
            if (empty($tid)) {
                AC::$errorNo = 'GRC001';
                return FALSE;
            }
            
            // 话题数据
            $topic = $this->topicModel->getTopicDetail($tid);
            if (empty($topic)){
                AC::$errorNo = 'GRC002';
                return FALSE;
            }
            
            // 查看权限
            $access =   $this->checkAccessPremission($topic['uid']);
            if (empty($access)) return  FALSE;
            
            // 话题详情
            $result = array();
            $result['topic_info'] 	= 	$this->topicModel->assembleTopicDetailData($this->autoUidModel, $topic, $host_uid);
            
            // 话题评论列表
            $list =   $this->topicCommentsModel->getTopicComments($tid, $topic['uid'], 0, 0, 10);
            $comments = $this->getComments($list, $host_uid);
            $result['topic_info']['comment_list']['comments'] = $comments;
            $result['topic_info']['comment_list']['counts']   = count($comments);
            
            // 查看数自增
            $this->topicModel->addViewNum(array('tid' => $tid));
            
            return $result;
        }
        
        /**
         * 对评论结果集进行处理
         * @param unknown $list
         * @return multitype:|multitype:Ambigous <unknown, multitype:string multitype: unknown >
         */
        private function getComments ($list, $host_uid = 0) {
            if (empty($list)) {
                return array();
            }
            
            $comments = array();
            foreach ($list as $value){
                if (intval($value['parentId']) > 0){
                    $comment = $this->topicCommentsModel->getCommentInfo($value['parentId'], $value['tid'], $value['author_uid']);
                    $value['extra']  =   UK::getstr($comment['content'], '100','',1);
                    if ($comment['status'] > 0){
                        $value['extra'] = "此内容已被管理员删除";
                    }
                }
                $comments[] = $this->topicCommentData($value, $host_uid);
            }
            
            return $comments;
        }

        /**
         * 话题列表
         * @param unknown $list
         * @param unknown $group
         * @param number $digest
         * @param number $new
         * @return multitype:Ambigous <string, Ambigous>
         */
        private function getTopics ($list, $host_uid, $group = array(), $digest = 0, $new = 0) {
            $topics = array();
            foreach ($topics as $value) {
                // 圈子详情
                if ($group) {
                    $value['gname'] = $group['name'];
                    $value['gAvatar'] = $group['avatar'];
                }else{
                    $groupInfo      = $this->groupInfoModel->groupAddRedis($value['gid']);
                    if (empty($groupInfo)){
                        continue;
                    }
                    $value['gname'] = $groupInfo['name'];
                    $value['gAvatar'] = $groupInfo['avatar'];
                }
        
                $value['show_digest'] = $digest;
                $value['new_topic']   = $new;
                $list = $this->topicModel->assembleTopicDetailData($this->autoUidModel, $value, $host_uid);
                if(empty($digest) || empty($new)){
                    $list['time']	= UK::intDeal($list['last_reply']);
                }
                $topics[] = $list;
            }
        
            return $topics;
        }
        
        /**
         * 话题评论数据结构
         * @param unknown $info
         * @param unknown $host_uid
         * @return Ambigous <unknown, multitype:string multitype: unknown >
         */
        private function topicCommentData ($info, $host_uid) {
            $data = array();
            $data['id']			    = UK::intDeal($info['position']);
            $data['tid']			= UK::intDeal($info['tid']);
            $data['uid']			= UK::intDeal($info['uid']);
            $data['nickname']		= strval($info['nickname']);
            $data['author_uid']		= UK::intDeal($info['author_uid']);
            $data['author_name']	= strval($info['author_name']);
            $data['gid']		    = UK::intDeal($info['gid']);
            $data['rUid']		    = UK::intDeal($info['rUid']);
            $data['rNickname']		= strval($info['rNickname']);
            $data['parentId']		= UK::intDeal($info['parentId']-1);
            $data['position']		= UK::intDeal($info['position']-1);
            $data['time']			= UK::intDeal($info['time']);
            $data['favorites'] 		= UK::intDeal($info['favorites']);
            $data['content']		= strval($info['content']);
            $data['extra']          = '';
            if (!empty($info['extra'])){
                $data['extra'] = strval(Emotion::emotionToCharacter($info['extra']));
            }
            
            // 判断评论是否被删除
            if ($info['status'] != '0'){
                $data['content']    =    '此内容已被管理员删除';
            }
            
            // 附件
            $data['attachments']    = array();
            $data['voiceList']    	= array();
            if ((intval($info['attachment']) > 0 || intval($info['voice']) > 0) && $info['status'] == 0){
                $attachment    	= $this->attachmentModel->getAttachmentInfo(array('pid' => $info['position'],'uid' => $info['author_uid'], 'tid' => $info['tid']));
                $data['attachments'] =    $attachment['attachmentList'];
                $data['voiceList']   =    $attachment['voiceList'];
            }
            $data['content'] = UK::tipsUpgrade($info['voiceList'], $data['content'], 'voice');
        
            // 表情对应的列表
            $data['imageList'] = array();
            $emotion_ids_mebuy = array();
            if ($info['extend']){
                $extend_arr     = json_decode($info['extend'], TRUE);
                $emotion_ids_mebuy = $extend_arr['shop_ids_mebuy'];
            }
        
            if (empty($emotion_ids_mebuy) && $info['time'] < Emotion::$filter_emotion_update_time){
                $emotion_ids_mebuy = Emotion::$default_emotion_ids;
            }
            $data['imageList'] = Emotion::emotionToImgList($data['content'], $emotion_ids_mebuy);
            $data['content']   = Emotion::emotionToMark($data['content'], $emotion_ids_mebuy);
            
            // 评论作者
            $data['url_struct']     =   array();
            $user			        =   $this->autoUidModel->getUserInfo($info['uid']);
            $data['user']           =   $this->autoUidModel->checkIsMe($user);
        
            // 获取备注名
            $user_author			=    $this->autoUidModel->getUserInfo($data['author_uid']);
            $data['author_name']    =    $this->autoUidModel->getRemarkName(array('uid'=>$data['author_uid'],'nickname'=>$user_author['nickname']));
            $data['nickname']       =    $this->autoUidModel->getRemarkName(array('uid'=>$data['uid'],'nickname'=>$data['user']['nickname']));
            $data['user']['nickname']   =  $data['nickname'];
            if (!empty($data['rUid']) && !empty($data['rNickname'])){
                $user_reply			    =    $this->autoUidModel->getUserInfo($data['rUid']);
                $data['rNickname']      =    $this->autoUidModel->getRemarkName(array('uid' => $data['rUid'], 'nickname' => $user_reply['nickname']));
            }

            // 是否当前用户收藏
            $data['is_favor'] 		= '0';
            if ($data['position'] > 0) {
                $favor = $this->topicModel->getFavoriteTopicInfo(array('uid' => $host_uid,'tid' => $data['tid'], 'position' => $info['position']));
                if (!empty($favor) && $favor['status'] == 0) {
                    $data['is_favor'] = '1';
                }
            }
        
            // 活动跳转数据组装
            if($info['position'] == 1 && !empty($info['url_struct'])){
                $data_url_struct = array(
                    'url_title'    =>    '',
                    'url_content'  =>    '',
                    'url_image'    =>    '',
                    'url_action'   =>    '',
                    'url_extend'   =>    array()
                );
        
                $url_struct = json_decode($info['url_struct'], true);
                isset($url_struct['url_title'])      &&    $data_url_struct['url_title']      =    strval($url_struct['url_title']);
                isset($url_struct['url_content'])    &&    $data_url_struct['url_content']    =    strval($url_struct['url_content']);
                isset($url_struct['url_image'])      &&    $data_url_struct['url_image']      =    strval($url_struct['url_image']);
                isset($url_struct['url_action'])     &&    $data_url_struct['url_action']     =    strval($url_struct['url_action']);
                isset($url_struct['url_extend'])     &&    $data_url_struct['url_extend']     =    $url_struct['url_extend'];
                $data['url_struct'][] = $data_url_struct;
            }
        
            return $data;
        }
        
        /**
         * 权限判断
         * @param unknown $uid
         * @return boolean
         */
	    private function checkAccessPremission ($uid) {
	        if ((AC::HOST_UID   ==  $uid))  return  TRUE;
	    
	        $array      =   array('uid' => AC::HOST_UID, 'fUid' => $uid, 'alarm' => TRUE);
	        $isBlackMe  =   $this->followModel->isBlackMe($array);
	        if (empty($isBlackMe))  return  TRUE;
	    
	        return  FALSE;
	    }
	    
	    /**
	     * 路由
	     * @param unknown $action
	     * @return boolean|string
	     */
	    private function checkAction ($action) {
	    	if (in_array($action, $this->actions) && method_exists($this, $action))  return  TRUE;
	    	AC::$errorNo    =   'SA004';
	    	return  ' Error : call do is not exists in GroupController! ';
	    }
	}